我们正在使用以下脚本在Windows服务器上安装MSI文件,并且能够在Windows服务器中安装MSI文件。下面的代码在一些MSI文件中运行良好,但对于其他文件却失败了。得到1603的出口代码。如果我们进行干净的安装,它可以正常工作,但是在尝试重新安装时,我们得到了一个退出代码:1603错误。对于所有服务,所有配置设置都是相同的。
作为在Microsoft网站上提到。,我们验证了以下条件,但没有适用于我们的情况。
代码:
: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
}
发布于 2020-11-09 20:30:16
如果使用MSI,则需要使用Start-Process msiexec.exe -wait -NoNewWindow
而不是Wait-Process
。如果您真的担心它会永远运行,请考虑使用PowerShell作业:
Start-Job -Name MyInstall -scriptBlock {
Start-Process msiexec.exe -NoNewWindow -ArgumentList $MSIArguments
}
Wait-Job -Name MyInstall
然后检查作业Get-Job MyInstall
的输出、状态消息、状态、错误,特别是子作业。
如果您的Start-Process
创建了尚未结束的子进程,则可能是由于相互竞争的安装尝试而导致的错误。尝试使用类似于凯文·马奎特解决方案的方法来保存冗长的MSI日志:
$MSI = 'C:\path\to\msi.msi'
$DateStamp = get-date -Format yyyyMMddTHHmmss
$logFile = "$MSI-$DateStamp.log"
$MSIArguments = @(
"/i"
"`"$MSI`""
"/qn"
"/norestart"
"/L*v"
$logFile
)
Start-Process "msiexec.exe" -ArgumentList $MSIArguments -Wait -NoNewWindow
https://stackoverflow.com/questions/64754999
复制相似问题