我有一个.ps1脚本来安装一个带有等待进程的软件,这个进程是在一台W7机器上用ISE创建的,当我试图在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我尝试更改名称以匹配任务管理器中显示的内容,但没有成功;我得到了相同的错误消息。注意:这个进程是一个在命令上运行的进程,我不需要验证它是否正在运行,我知道它正在运行,我只需要知道它运行的是什么。
有什么想法或建议吗?
发布于 2017-06-30 15:46:29
在安装过程中,请使用另一个PowerShell窗口运行以下内容,以了解PowerShell对该进程的看法。
Get-Process | Where-Object {$_.path -match "EnterpriseRx.exe"}它很可能将进程名简单地看作是"EnterpriseRx“,而没有.exe的结尾。
发布于 2017-06-30 17:03:13
另一种尝试是,通过Start-Process启动进程,因为这个Cmdlet将返回您的进程对象。您可以利用这个来等待:
#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-Processhttps://stackoverflow.com/questions/44849956
复制相似问题