Wait-Process在Windows 10中不起作用

时间:2017-06-30 15:25:05

标签: powershell windows-10

我有一个.ps1脚本,用于在W7机器上使用ISE创建的Wait-Process安装一个软件,当我尝试在W10上运行时,它会出错。这是脚本直到失败:

#Runs EnterpriseRx installer configured for PROD:
.\"EnterpriseRx.exe" /q /installType=0 /facilityID=999 /targetEnv=PROD 
/encryptFacility=0 /S /D=C:\McKesson\EnterpriseRx Production

#15 second notification letting user know install is running:
$wshell = New-Object -ComObject Wscript.Shell
$wshell.Popup("This process typically takes about 1 minute.  You will be 
notified when install is complete.",15,"EnterpriseRx - PROD is 
installing...",0x1)

#Wait for application to finish installing:
Wait-Process -name "EnterpriseRx.exe"

返回的错误是:

Wait-Process : Cannot find a process with the name "EnterpriseRx.exe". 
Verify the process name and call the cmdlet again.
At C:\temp\EnterpriseRx Install TEST\EnterpriseRx Production - Desktop.ps1:9 
char:1
+ Wait-Process -name "EnterpriseRx.exe"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (EnterpriseRx.exe:String) [Wait-
Process], ProcessCommandException
+ FullyQualifiedErrorId : 
NoProcessFoundForGivenName,Microsoft.PowerShell.Commands.WaitProcessCommand

我尝试更改名称以匹配任务管理器中显示的名称,但没有成功;我收到相同的错误消息。注意:此过程是一个run-on-command.exe,我不需要验证如果它正在运行,我知道它正在运行,我只需要知道它正在运行

有任何想法或建议吗?

2 个答案:

答案 0 :(得分:0)

在您的安装过程中,使用另一个PowerShell窗口运行以下内容以了解PowerShell对该过程的看法。

Get-Process | Where-Object {$_.path -match "EnterpriseRx.exe"}

最有可能将进程名称视为“EnterpriseRx”而不是最终的.exe。

答案 1 :(得分:0)

另一个尝试是,按Start-Process启动进程,因为此Cmdlet将返回您的Process-Object。你可以利用它来等待:

#Runs EnterpriseRx installer configured for PROD:

$Process = Start-Process .\"EnterpriseRx.exe" -ArgumentList /q, /installType=0, /facilityID=999, /targetEnv=PROD, 
/encryptFacility=0, /S, /D=C:\McKesson\EnterpriseRx, Production -PassThru 

#15 second notification letting user know install is running:
$wshell = New-Object -ComObject Wscript.Shell
$wshell.Popup("This process typically takes about 1 minute.  You will be 
notified when install is complete.",15,"EnterpriseRx - PROD is 
installing...",0x1)

#Wait for application to finish installing:
$Process | Wait-Process