【发布时间】:2020-11-09 15:59:36
【问题描述】:
我们正在尝试使用以下脚本在 Windows 服务器上安装 MSI 文件,并且能够在 Windows 服务器中安装 MSI 文件。以下代码适用于某些 MSI 文件,但对于其他文件则失败。将退出代码设为 1603。如果我们进行全新安装,它工作正常,但在尝试重新安装时,我们收到退出代码:1603 错误。所有服务的所有配置设置都相同。
作为mentioned on the Microsoft web site,我们验证了以下条件,没有一个适用于我们的案例。
-
Windows Installer 正在尝试安装您的 PC 上已安装的应用。
-
您尝试安装 Windows 的文件夹 安装程序包已加密。
-
包含您尝试安装 Windows Installer 程序包的文件夹的驱动器将作为替代驱动器访问。
-
SYSTEM 帐户对您尝试将 Windows 安装程序包安装到的文件夹没有完全控制权限。您注意到错误消息是因为 Windows Installer 服务使用 SYSTEM 帐户安装软件。
代码:
:outer for($i=1; $i -le $attempts; $i++) {
$timeout = $null
$proc = Start-Process -filePath $InstallerPath -ArgumentList $InstallCommand -PassThru
$proc | Wait-Process -Timeout $SecondsToWait -ea 0 -ev timeout
If (($timeout) -or ($proc.ExitCode -ne 0)) {
$proc | kill
$error = "`tFailed To Run $($ProcessTitle)Operations: Exit-Code = $($proc.ExitCode)"
If(($i+1) -le $attempts) {
WriteLog -Message($error) -MainLoggingConfigs $MainLoggingConfigs
Start-Sleep -s $WaitTimePerAttempt
}
Else {
throw $error
}
}
Else {
break outer
}
【问题讨论】:
-
-filePath $InstallerPath -ArgumentList $InstallCommand$InstallerPath和$InstallComand的值将有助于回答
标签: powershell windows-installer exit-code