gpt4 book ai didi

powershell - 等待使用凭据启动的进程时访问被拒绝

转载 作者:行者123 更新时间:2023-12-05 05:16:38 24 4
gpt4 key购买 nike

我有一个脚本在没有安装应用程序权限的用户的用户上下文中运行。我需要安装一个 exe,所以我需要以域管理员的身份安装。

安装后我想在脚本中做其他事情,但必须先完成安装才能继续脚本。

当我Wait-Process 安装结束时,出现访问被拒绝错误。

有没有办法等待在另一个用户上下文中启动的进程完成?

这是我的代码:

$P = Start-Process $Pfad\vcredist_x64.exe -Argumentlist "/install","/passive","/norestart" `
-WorkingDirectory $Pfad -Credential $cred -PassThru | Wait-Process

这是错误信息(翻译自德语):

访问被拒绝

Wait-Process : This command terminated the "vcredist_x64 (6284)" operation due to the following error: Access denied. In Zeile:6 Zeichen: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 : This command terminated the process because the "vcredist_x64 (6284)" process was not completed within the specified timeout. In Zeile:6 Zeichen:84 + ... -WorkingDirectory $Pfad -Credential $cred -PassThru | Wait-Process + ~~~~~~~~~~~~ + CategoryInfo : CloseError: (System.Diagnost... (vcredist_x64):Process) [Wait-Process], TimeoutException + FullyQualifiedErrorId : ProcessNotTerminated,Microsoft.PowerShell.Commands.WaitProcessCommand

最佳答案

张贴我之前的评论作为答案

$proc = Start-Process "Notepad.exe" -PassThru
$proc.WaitForExit()
$proc1 = Start-Process "Calc.exe" -PassThru
$proc1.WaitForExit()

关于powershell - 等待使用凭据启动的进程时访问被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50170337/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com