How to set exit code in Inno Setup?

I want to set an exit code for my installation, so I will find out why the installation was interrupted. I am using Inno Setup.

+7
exit-code inno-setup
source share
2 answers

Using:

[Code] procedure ExitProcess(exitCode:integer); external 'ExitProcess@kernel32.dll stdcall'; procedure SomeEventHere(); begin if someerror then begin ExitProcess(9); //Your custom exit code end; end; 
+7
source share

From the Inno Setup help document ( from the article “Installation exit codes” ):

Starting with Inno Setup 3.0.3, Setup can return one of the following exit codes:

0 Setup completed successfully.

1 Failed to initialize installation.

2 The user clicked “Cancel” in the wizard before starting the actual installation or selected “No” in the “This will install ...” message box.

3 A fatal error occurred while preparing for the transition to the next installation phase (for example, from displaying the pages of the installation wizard to the actual installation process). This should never happen, except in the most unusual circumstances, such as a lack of memory or Windows resources.

4 A fatal error occurred during the actual installation process.

Note. Errors that cause an interrupt-re-ignore display are not fatal errors. If the user selects Abort in this message box, return code 5 returned.

5 The user clicked “Cancel” during the actual installation process or selected “Abort” in the “Abort-repeat ignore” field.

6 The installation process was forcibly completed by the debugger (Run | Terminate was used in the IDE).

You can easily check if the installation is running successfully by confirming that the exit code is 0 . Besides:

Any non-zero exit code indicates that the installation was not completed.

To more accurately answer your question, you can determine that the installation was canceled by observing exit code 2 or 5 .

If you want to return a custom exit code when Inno otherwise returns 0 , you can define the following event function:

 function GetCustomSetupExitCode: Integer; 

From the reference document ( from the article "Pascal Scripting: Event Functions" ):

function GetCustomSetupExitCode: Integer;

Return a nonzero number to tell Setup to return a custom exit code. This function is called only if the setup program was successfully launched before completion and the exit code is 0 .

+11
source share

All Articles