How can I set the exit code in Inno Setup?

﹥>﹥吖頭↗ 提交于 2020-01-11 02:31:07

问题


I want to set the exit code for my installation, this way I will know why the installation was aborted. I'm using Inno Setup.


回答1:


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;



回答2:


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.



来源:https://stackoverflow.com/questions/2013112/how-can-i-set-the-exit-code-in-inno-setup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!