是否可以禁用 msiexec 帮助 GUI?

sno*_*gle 5 windows powershell windows-installer msi

我正在使用 powershell 脚本自动无人值守地检索和安装指定的 .msi 包,但如果调用命令时出现语法错误,尽管存在 /quiet 和/或 /passive,msiexec 将无限期地等待对其帮助显示的确定单击.

目前我正在调用它:

(start-process -FilePath "msiexec" -ArgumentList "/i <path_to_package> /quiet /passive" -PassThru -Wait).ExitCode
Run Code Online (Sandbox Code Playgroud)

有没有办法禁用 msiexec 帮助显示?

jsc*_*ott 5

对于msiexec包含语法错误的命令,无法禁用此行为。您可以将命令包装成如下所示的内容。它使用 .NET 自动化来查找“使用”窗口并在脚本中处理它。

Add-Type -AssemblyName UIAutomationClient
Add-Type -AssemblyName UIAutomationTypes

# Note the invalid argument '/badswitch'
$mse = Start-Process -FilePath 'msiexec' -ArgumentList "/i package.msi /badswitch /quiet /passive" -PassThru

# Let msiexec at least get off the ground
[void] $mse.WaitForInputIdle()

# Create an AutomationElement from $mse's handle
$mseAuto = [Windows.Automation.AutomationElement]::FromHandle($mse.MainWindowHandle)

# A PropertyCondition for findAll()
$pane = New-Object Windows.Automation.PropertyCondition -ArgumentList (
    [Windows.Automation.AutomationElement]::ControlTypeProperty,
    [Windows.Automation.ControlType]::Pane
)

# Search for a child $pane element.
$findResult = $mseAuto.FindFirst(
    [System.Windows.Automation.TreeScope]::Children,
    $pane
)

# If there's a pane element in $mseAuto, and it contains "usage" string, it's an msiexec syntax issue, so close $mse's window.
if ( $findResult.Current.Name -match 'msiexec /Option <Required Parameter>' ) {
    [void] $mse.CloseMainWindow()
} else {
    # You should put something more sane here to handle waiting for "good" installs to complete.
    $mse.WaitForExit()    
}

$mse.ExitCode
Run Code Online (Sandbox Code Playgroud)

这也有问题。随着/quiet一个进度对话框在安装过程中仍然显示。您可以考虑使用/qn代替隐藏所有msiexecUI 元素。同样,MSI 可能会触发其他未处理的错误,这将暂停执行不忠。也许包括超时值?什么是从 CustomAction 表启动的外部进程?对不起,我现在快要闲逛了……


Kat*_*ard 4

可悲的是,我认为避免显示帮助的唯一方法是......

...不要犯任何拼写错误/语法错误。

我希望我能为你提供更好的答案,但是......