I want to set the exit code for my installation, this way I will know why the installation w开发者_如何学JAVAas aborted. I'm using Inno Setup.
From the Inno Setup Help document (from the article "Setup Exit Codes"):
Beginning with Inno Setup 3.0.3, the Setup program may return one of the following exit codes:
0 Setup was successfully run to completion.
1 Setup failed to initialize.
2 The user clicked Cancel in the wizard before the actual installation started, or chose "No" on the opening "This will install..." message box.
3 A fatal error occurred while preparing to move to the next installation phase (for example, from displaying the pre-installation wizard pages to the actual installation process). This should never happen except under the most unusual of circumstances, such as running out of memory or Windows resources.
4 A fatal error occurred during the actual installation process.
Note: Errors that cause an Abort-Retry-Ignore box to be displayed are not fatal errors. If the user chooses Abort at such a message box, exit code
5
will be returned.5 The user clicked Cancel during the actual installation process, or chose Abort at an Abort-Retry-Ignore box.
6 The Setup process was forcefully terminated by the debugger (Run | Terminate was used in the IDE).
You can easily check if the setup ran successfully by confirming that the exit code is 0
. Furthermore:
Any non-zero exit code indicates that Setup was not run to completion.
To answer your question more specifically, you can determine the installation was canceled by observing exit code 2
or 5
.
If you wish to return a custom exit code when Inno would otherwise return 0
, you can define the following event function:
function GetCustomSetupExitCode: Integer;
From the help document (from the article "Pascal Scripting: Event Functions"):
function GetCustomSetupExitCode: Integer;
Return a non zero number to instruct Setup to return a custom exit code. This function is only called if Setup was successfully run to completion and the exit code would have been
0
.
Use:
[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;
精彩评论