How to detect if I need to prompt user to restart PC after installing VC Redist package(s)

0

I had an issue on someone’s computer yesterday where my installer did not complete as expected. I connected to their PC to investigate.

It had to do with the VC Redist files. My installer detects if these are needed and if required, downloads and installs them.

I use the command line switches so that the user is not prompted at all and the I use the /norestart flag as my installer has to complete.

The problem was that VC Redist needed them to restart the PC. I found this out by running my installer, it downloaded the Redist setup and attempted to install. My setup aborted. So I tried to manually run the VC Redist Setup and that is where I saw it say the pc needed a reboot.

So, how can I either test if the Redist requires a pc restart and then get my installer to convey this to the user, or, how can I just prompt the user to user if either of the VC Redist setups had been spawned?

I did find this:

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

And I noticed the last entry:

ERROR_SUCCESS_REBOOT_REQUIRED 3010    

A restart is required to complete the install. This message is indicative of a success. This does not include installs where the ForceReboot action is run.

0xBC2 0x80070BC2

This is how I spawn the installers at the moment:

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;
inno-setup
pascalscript
vcredist
asked on Stack Overflow Jul 17, 2020 by Andrew Truckle • edited Jul 17, 2020 by Andrew Truckle

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0