从 PowerShell 运行 MsiExec 并获取返回代码 [英] Run MsiExec from PowerShell and get Return Code

查看:43
本文介绍了从 PowerShell 运行 MsiExec 并获取返回代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 BAT/CMD 脚本,我可以简单地使用 "msiexec/i /quiet/norestart" 然后检查 %errorlevel% 结果.

With BAT/CMD script I can simply use "msiexec /i <whatever.msi> /quiet /norestart" and then check %errorlevel% for the result.

使用VBScript,使用Wscript.Shell对象Run()方法,我可以得到这样的结果:

With VBScript, using the Wscript.Shell object Run() method, I can get the result like this:

"result = oShell.Run("msiexec /i ...", 1, True)"

如何使用 PowerShell 执行此操作?

How can I do this with PowerShell?

推荐答案

我会将其封装在 Start-Process 中,并使用结果进程对象的 ExitCode 属性.例如

I would wrap that up in Start-Process and use the ExitCode property of the resulting process object. For example

(Start-Process -FilePath "msiexec.exe" -ArgumentList "<<whatever>>" -Wait -Passthru).ExitCode

这篇关于从 PowerShell 运行 MsiExec 并获取返回代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆