【问题标题】:While installing msi using PowerShell command Start-Process, getting Exit-code 1603 error使用 PowerShell 命令 Start-Process 安装 msi 时,出现 Exit-code 1603 错误
【发布时间】: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


【解决方案1】:

如果使用 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 创建了尚未结束的子进程,您收到的错误可能是由于竞争安装尝试造成的。尝试使用类似Kevin Marquette's 的解决方案来保存详细的 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

【讨论】:

  • 感谢您的宝贵时间和回复。我会落实您的建议并试一试。
猜你喜欢
  • 2017-11-17
  • 2015-02-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-23
相关资源
最近更新 更多