英文:
Powershel Get Elevated process ExitCode
问题
我正在尝试以静默方式安装应用程序,但由于我正在以提升的权限运行,无法获得正确的退出代码。
请注意,$Credetial 正试图使用另一个具有管理员权限的本地用户进行安装。
$tab = "C:\Tab Server"
$tabInstaller = "D:\TabInstaller\TabServer-64bit.exe"
$tablog = "C:\Temp\Tableaulog\TabInstaller.log"
$command = "-noprofile -command ""Start-Process cmd.exe -Verb RunAs -ArgumentList '/c ""$tabInstaller"" /silent /install ACCEPTEULA=1 ACTIVATIONSERVICE=0 ""INSTALLDIR=$($drive)"" /log $tablog'"""
[int]$result = (Start-Process "powershell.exe" -Credential $credential -ArgumentList $command -NoNewWindow -Wait -Passthru).ExitCode
我尝试通过在命令提示符中传递 echo %ERROLEVEL%
来获取退出代码,但未成功。
英文:
I am trying to install an application silently but I could not get the proper exit code since I am running elevated privilege.
Note $Credetial trying to install with another local user with admin privilages.
$tab = "C:\Tab Server"
$tab = "D:\TabInstaller\TabServer-64bit.exe"
$tablog = "C:\Temp\Tableaulog\TabInstaller.log"
$list = "-noprofile -command ""Start-Process cmd.exe -Verb RunAs -ArgumentList '/c ""$tab"" /silent /install ACCEPTEULA=1 ACTIVATIONSERVICE=0 """"""INSTALLDIR=$($drive)"""""" ""/log $tablog""'"""
[int]$result = (Start-Process "powershell.exe" -Credential $credential -ArgumentList $list -NoNewWindow -Wait -Passthru).ExitCode
I tried to get the exit code by trying to pass echo %ERROLEVEL% in the command prompt but it did not work.
答案1
得分: 0
You're using -Wait
and -PassThru
combined with .ExitCode
in the outer Start-Process
call, but you must also apply it to the inner one, so as to make the outer call relay the inner's exit code, via an exit
statement:
$list = "-noprofile -command ""exit (Start-Process -Wait -PassThru -Verb RunAs cmd.exe -ArgumentList '/c ""$tab"" /silent /install ACCEPTEULA=1 ACTIVATIONSERVICE=0 """"""INSTALLDIR=$($drive)"""""" ""/log $tablog""'").ExitCode"""
(Note: I've translated the text within the code block as requested, but the code itself remains in its original form.)
英文:
You're using -Wait
and -PassThru
combined with .ExitCode
in the outer Start-Process
call, but you must also apply it to the inner one, so as to make the outer call relay the inner's exit code, via an exit
statement:
$list = "-noprofile -command ""exit (Start-Process -Wait -PassThru -Verb RunAs cmd.exe -ArgumentList '/c ""$tab"" /silent /install ACCEPTEULA=1 ACTIVATIONSERVICE=0 """"""INSTALLDIR=$($drive)"""""" ""/log $tablog""'").ExitCode"""
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论