0

我昨天在某人的计算机上遇到问题,我的安装程序没有按预期完成。我连接到他们的电脑进行调查。

它与 VC Redist 文件有关。我的安装程序检测是否需要这些,如果需要,下载并安装它们。

我使用命令行开关,因此根本不会提示用户,并且我使用 /norestart 标志,因为我的安装程序必须完成。

问题是 VC Redist 需要他们重新启动 PC。我通过运行我的安装程序发现了这一点,它下载了 Redist 设置并尝试安装。我的设置中止了。所以我尝试手动运行 VC Redist 安装程序,这就是我看到它说电脑需要重新启动的地方。

那么,我该如何测试 Redist 是否需要重新启动电脑,然后让我的安装程序将其传达给用户,或者,如果任何一个 VC Redist 设置已经产生,我如何才能提示用户给用户?

我确实找到了这个:

https://johnkoerner.com/install/windows-installer-error-codes/

我注意到最后一个条目:

ERROR_SUCCESS_REBOOT_REQUIRED 3010    

需要重新启动才能完成安装。此消息表示成功。这不包括运行 ForceReboot 操作的安装。

0xBC2 0x80070BC2

这就是我目前生成安装程序的方式:

procedure CurStepChanged(CurStep: TSetupStep);
var
    ResultCode: integer;
    strLogFilePathName, strLogFileName, strNewFilePathName: string;
begin
    if (CurStep = ssDone) then
    begin
        strLogFilePathName := ExpandConstant('{log}');
        strLogFileName := ExtractFileName(strLogFilePathName);
        strNewFilePathName := ExpandConstant('{#CommonDataDir}\Installation Logs\') + strLogFileName;

        FileCopy(strLogFilePathName, strNewFilePathName, false);
    end
    else if (CurStep = ssPostInstall) then
    begin
        if (dotNetNeeded) then
        begin
            (* See here for command line switches:
                https://docs.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/ee942965(v=vs.100)
                Do I use passive or showfinalerror? *)
            if Exec(ExpandConstant(dotnetRedistPath), '/passive', '',
                    SW_SHOW, ewWaitUntilTerminated, ResultCode) then begin
                { handle success if necessary; ResultCode contains the exit code }
                if not (ResultCode = 0) then begin
                    (* Microsoft present an array of options for this. But since
                         The interface was visible I think it is safe to just say
                         that the installation was not completed. *)
                    MsgBox(ExpandConstant('{cm:InstallFailed,Microsoft .NET Framework 4.6.2}'), mbInformation, MB_OK);
                    Abort();
                end;
            end
            else begin
                { The execution failed for some reason }
                MsgBox(SysErrorMessage(ResultCode), mbInformation, MB_OK);
                Abort();
            end;
        end;
        
        if (bVcRedist64BitNeeded) then
        begin
            if Exec(ExpandConstant(vcRedist64BitPath), '/install /passive /norestart', '',
                    SW_SHOW, ewWaitUntilTerminated, ResultCode) then begin
                { handle success if necessary; ResultCode contains the exit code }
                if not (ResultCode = 0) then begin
                    MsgBox(ExpandConstant('{cm:InstallFailed,Visual Studio x64 Redistributable}'), mbInformation, MB_OK);
                    Abort();
                end;
            end
            else begin
                { The execution failed for some reason }
                MsgBox(SysErrorMessage(ResultCode), mbInformation, MB_OK);
                Abort();
            end;
        end;

        if (bVcRedist32BitNeeded) then
        begin
            if Exec(ExpandConstant(vcRedist32BitPath), '/install /passive /norestart', '',
                    SW_SHOW, ewWaitUntilTerminated, ResultCode) then begin
                { Handle success if necessary; ResultCode contains the exit code }
                if not (ResultCode = 0) then begin
                    MsgBox(ExpandConstant('{cm:InstallFailed,Visual Studio x86 Redistributable}'), mbInformation, MB_OK);
                    Abort();
                end;
            end
            else begin
                { The execution failed for some reason }
                MsgBox(SysErrorMessage(ResultCode), mbInformation, MB_OK);
                Abort();
            end;
        end;
  end;
end;
4

0 回答 0