【发布时间】:2017-05-21 20:33:12
【问题描述】:
大家好,我正在尝试在远程系统上启动一个 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
#Starts Process# 最后运行没有错误,但远程机器上没有任何反应,终止进程工作正常。任何帮助将不胜感激。
【问题讨论】:
-
在很多情况下,看起来代码在粘贴后可能已放在新行上。例如,在最后一行中,如果
$WBSTART实际上位于单独的行上,那么这就是您的问题。此外,您似乎没有任何代码来停止进程或使用您创建的会话。有什么遗漏吗? -
对不起,我更新了代码
-
是否有可能 $mycreds 用户无权访问 .exe 所在的路径?
标签: windows powershell powershell-remoting