2
votes

I've been using Inno Setup for several months now, but I'm struggling to find how to detect, from within the installer itself, an error that would cause Inno Setup to end with a non-zero exit code.

I've thought about using CurStepChanged with the ssDone step, or even DeinitializeSetup, but I can't find how to get access to the wizard's exit-code.

Did I miss something? There must be a way to do it...

I'd like to know if anything went wrong so that I can start a rollback procedure on the machine. Your proposed answer did the trick.

1

1 Answers

3
votes

You cannot find out installer exit code from the Pascal Scripting.


If you want to detect that the installer failed, remember if CurStepChanged was called with ssDone and test that in DeinitializeSetup.

var
  Succeeded: Boolean;

procedure DeinitializeSetup();
begin
  if Succeeded then
  begin
    Log('Installation succeeded');
  end
    else
  begin
    Log('Installation failed');
  end;
end;

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssDone then
  begin
    Succeeded := True;
  end;
end;

There are edge cases, when ssDone is used even, if the installer fails.

For example, when it fails because a machine was not restarted to complete the previous installation. In this case the CurStepChanged is not called with ssPostInstall. So you may want to check for both steps, if this scenario can happen in your installer.