大家好,我想在远程系统上启动一个exe文件。我们有一个代理程序,用于连接我们的网站、数据库和打印机。它偶尔会挂起,需要我们远程登录或去工作站重新启动应用程序。我已经尝试了许多不同的解决方案,但都没有成功。
我能够结束正在运行的进程,但是它将无法重新打开exe文件以再次启动它。以下是目前的小脚本:
################################################
write-host "This will Restart Workbench helper please press the any key to start"
pause
$mycreds = Get-Credential
$computer = Read-Host -prompt "Please Enter Computer Name"
$WBSTART1 = Read-Host -prompt "please enter command"
$pers = New-PSSession -ComputerName $computer -Credential $mycreds
# Gets Computer Name and Kills Workbench Helper #
(Get-WmiObject win32_process -ComputerName $computer -Credential $mycreds | ?{ $_.ProcessName -match "Workbench3.helper" }).Terminate()
# Writes Host countdown to screen #
write-host -ForegroundColor black -NoNewline "Stopping Process"
foreach ($element in 1..10)
{
Write-Host -NoNewline "${element} " -BackgroundColor 'white' - ForegroundColor 'black'
Start-Sleep -Seconds 1
}
Write-Host ''
Write-host "Process Complete"
Start-Process -filepath "C:\Program Files (x86)\Company Security\Workbench3 Helper\WorkBench3.Helper.exe"
# Writes Host countdown to termination Screen #
write-host -ForegroundColor black -NoNewline "Starting Workbench Process"
foreach ($element in 1..10)
{
Write-Host -NoNewline "${element} " -BackgroundColor 'white' -ForegroundColor 'black'
Start-Sleep -Seconds 1
}
Write-Host ''
Write-host "Process Complete"
# Starts Process #
$WBSTART = {start-process -filepath 'C:\Program Files (x86)\FrontPoint Security\Workbench3 Helper\WorkBench3.Helper.exe'}
Invoke-Command –ComputerName $computer -Credential $mycreds -ScriptBlock $WBSTART
#启动进程#在结束时没有错误,但远程机器上没有任何反应,杀死进程可以正常工作。如有帮助将不胜感激。
$WBSTART
实际上是单独一行,那么这就是你的问题所在。此外,似乎你没有任何代码来停止进程或使用你创建的会话。是否有遗漏的部分? - Patrick Meinecke