如何在PowerShell中远程启动进程

编程入门 行业动态 更新时间:2024-10-10 19:26:53
本文介绍了如何在PowerShell中远程启动进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有问题,我有一个脚本,其中:

I have a problem, I have a script which:

  • 与PSSession连接(我在管理员帐户中使用PSSession)
  • 停止2进程
  • 对文件进行更改
  • 开始2步(问题在这里)
  • Connect with PSSession (I use PSSession with admin account)
  • Stop 2 process
  • Do change on them files
  • Start the 2 process (Problem here)

我想在服务器上启动进程,所以我要连接PSSession(没问题)

I want to start process on server, so i'm connect with PSSession (No problem)

我执行调用命令:

# $pathProg path to my program Invoke-Command -session $mySession -command {Start-Process $($args[0])} -ArgumentList $pathProg

但是它什么也没做(我已通过VNC验证)

But it does nothing (I verify with VNC)

我也执行Invoke-Command:

I do Invoke-Command too :

# $pathProg path to my program Invoke-Command -session $mySession -command {&$($args[0])} -ArgumentList $pathProg

它无法执行程序(很好),但是我的脚本等待结束程序(不好)

It lauch the program (Good) but my script wait the end program (Not good)

有人有主意吗?

谢谢

推荐答案

您可以尝试使用WMI:

You can try using WMI:

$command = "notepad.exe" $process = [WMICLASS]"\\$CompName\ROOT\CIMV2:win32_process" $result = $process.Create($command)

如果您需要通过凭据:

$cred = get-credential $process = get-wmiobject -query "SELECT * FROM Meta_Class WHERE __Class = 'Win32_Process'" -namespace "root\cimv2" -computername $CompName -credential $cred $results = $process.Create( "notepad.exe" )

更多推荐

如何在PowerShell中远程启动进程

本文发布于:2023-11-25 20:27:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1631229.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:进程   如何在   PowerShell

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!