繁体   English   中英

使用 PowerShell 命令 Start-Process 安装 msi 时,出现退出代码 1603 错误

[英]While installing msi using PowerShell command Start-Process, getting Exit-code 1603 error

我们正在尝试使用以下脚本在 Windows 服务器上安装 MSI 文件,并且能够在 Windows 服务器中安装 MSI 文件。 以下代码对某些 MSI 文件工作正常,但对其他人却失败了。 将退出代码设为 1603。如果我们进行全新安装,它可以正常工作,但在尝试重新安装时,我们收到退出代码:1603 错误。 所有服务的所有配置设置都相同。

正如在 Microsoft 网站上提到的,我们验证了以下条件并且没有条件适用于我们的案例。

  • Windows Installer 正在尝试安装已安装在您的 PC 上的应用程序。

  • 您尝试安装 Windows Installer 程序包的文件夹已加密。

  • 包含您尝试安装 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
    }

如果使用 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 的解决方案来保存冗长的 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM