安装完成后,我想在脚本中执行其他操作,但必须等待安装完成后才能继续脚本。
当我使用
Wait-Process
等待安装结束时,会出现访问被拒绝的错误。有没有一种方法可以等待在另一个用户上下文中启动的进程结束?
这是我的代码:
$P = Start-Process $Pfad\vcredist_x64.exe -Argumentlist "/install","/passive","/norestart" `
-WorkingDirectory $Pfad -Credential $cred -PassThru | Wait-Process
以下是错误信息的翻译(从德语翻译):
访问被拒绝
Wait-Process:此命令终止了“vcredist_x64(6284)”操作,原因是出现了以下错误:访问被拒绝。在第6行 字符:84 + ... -WorkingDirectory $Pfad -Credential $cred -PassThru | Wait-Process + ~~~~~~~~~~~~ + CategoryInfo : CloseError: (System.Diagnost... (vcredist_x64):Process) [Wait-Process], ProcessCommandException + FullyQualifiedErrorId : ProcessNotTerminated,Microsoft.PowerShell.Commands.WaitProcessCommand
超时问题
Wait-Process:此命令终止了进程,因为“vcredist_x64(6284)”进程未在指定的超时时间内完成。在第6行 字符:84 + ... -WorkingDirectory $Pfad -Credential $cred -PassThru | Wait-Process + ~~~~~~~~~~~~ + CategoryInfo : CloseError: (System.Diagnost... (vcredist_x64):Process) [Wait-Process], TimeoutException + FullyQualifiedErrorId : ProcessNotTerminated,Microsoft.PowerShell.Commands.WaitProcessCommand
-wait
也会出现访问被拒绝的情况,WaitForExit()
似乎根本不起作用。 - SimonSWaitForExit
怎么样了,非常感谢! - SimonS