如何在 Inno Setup 中设置退出代码?

发布于 2024-08-16 19:34:38 字数 54 浏览 12 评论 0原文

我想为我的安装设置退出代码,这样我就能知道为什么安装被中止。我正在使用 Inno Setup。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

可是我不能没有你 2024-08-23 19:34:38

来自 Inno Setup 帮助文档(来自文章“安装程序退出代码” ):

从 Inno Setup 3.0.3 开始,安装程序可能会返回以下退出代码之一:

0安装程序已成功运行完成。

1安装程序初始化失败。

2 用户在实际安装开始之前在向导中单击了“取消”,或者在打开的“这将安装...”消息框中选择了“否”。

3 准备进入下一个安装阶段(例如,从显示预安装向导页面到实际安装过程)时发生致命错误。除非是在最不寻常的情况下,例如内存或 Windows 资源耗尽,否则这种情况永远不会发生。

4实际安装过程中出现致命错误。

注意:导致显示 Abort-Retry-Ignore 框的错误不是致命错误。如果用户在此类消息框中选择“Abort”,则会返回退出代码 5

5用户在实际安装过程中单击了“取消”,或者在“中止-重试-忽略”框中选择了“中止”。

6安装进程被调试器强制终止(IDE 中使用了“运行 | 终止”)。

您可以通过确认退出代码为 0 轻松检查设置是否成功运行。此外:

任何非零退出代码都表示安装程序未运行完成。

要更具体地回答您的问题,您可以通过观察退出代码 25 来确定安装已取消。

如果您希望在 Inno 返回 0 时返回自定义退出代码,您可以定义以下事件函数:

function GetCustomSetupExitCode: Integer;

来自帮助文档 (摘自文章“Pascal 脚本:事件函数”):

函数 GetCustomSetupExitCode: Integer;

返回一个非零数字以指示安装程序返回自定义退出代码。仅当安装程序成功运行完成且退出代码为 0 时才会调用此函数。

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.

二手情话 2024-08-23 19:34:38

使用:

[Code]
procedure ExitProcess(exitCode:integer);
  external '[email protected] stdcall';

procedure SomeEventHere();
begin
  if someerror then begin
    ExitProcess(9); //Your custom exit code
  end;
end;

Use:

[Code]
procedure ExitProcess(exitCode:integer);
  external '[email protected] stdcall';

procedure SomeEventHere();
begin
  if someerror then begin
    ExitProcess(9); //Your custom exit code
  end;
end;
或十年 2024-08-23 19:34:38

确实有同样的问题并找到了解决方法:

[Code]
var CustomExitCode: integer;

procedure ExitProcess(exitCode:integer);
    external '[email protected] stdcall';

procedure DeinitializeSetup();
begin
    if (CustomExitCode <> 0) then
    begin
        DelTree(ExpandConstant('{tmp}'), True, True, True);
        ExitProcess(CustomExitCode);
    end;
end;

现在在设置的任何时候只需将 CustomExitCode 设置为您想要的代码即可。
示例:

function InitializeSetup: Boolean;
begin
    // Some check did fail, exiting with custom code
    CustomExitCode = -1;
    
    // Let's just close the setup
    Result := false;
end;

这样安装程序就不会突然终止,并且无论向导以何种状态退出,您都可以自定义退出代码。

Did have this same question and found a way to it:

[Code]
var CustomExitCode: integer;

procedure ExitProcess(exitCode:integer);
    external '[email protected] stdcall';

procedure DeinitializeSetup();
begin
    if (CustomExitCode <> 0) then
    begin
        DelTree(ExpandConstant('{tmp}'), True, True, True);
        ExitProcess(CustomExitCode);
    end;
end;

And now at any point of your setup just set CustomExitCode to the code you want.
Example:

function InitializeSetup: Boolean;
begin
    // Some check did fail, exiting with custom code
    CustomExitCode = -1;
    
    // Let's just close the setup
    Result := false;
end;

This way the setup will not terminate abruptly and you can customize the exit code no matter what state the wizard did exit.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文