【问题标题】:How can I set the exit code from return code of my Execute File in Inno Setup?如何在 Inno Setup 中从我的执行文件的返回代码中设置退出代码?
【发布时间】:2015-12-11 03:16:11
【问题描述】:

我想从我的{app}\{#MyAppExeName} 获取返回码(负值)作为设置退出码(MyAppExeName 将运行 20~30 秒)

我参考了很多示例代码,Exec可以得到结果代码 但仍然不知道如何将设置退出代码添加到[Code] 部分(我不知道 Pascal 脚本)

下面是我的 Inno 设置脚本中的 [Run] 部分

[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent

如何根据我的目标更改[Run][Code] 部分?

请帮帮我,给我示例代码

谢谢

BR, 艾伦

【问题讨论】:

    标签: inno-setup exit-code


    【解决方案1】:

    使用Exec support function 运行外部进程并检索其退出代码。

    要修改安装程序的退出代码,请实现GetCustomSetupExitCode event function

    [Code]
    
    var
      ExitCode: Integer;
      
    procedure CurStepChanged(CurStep: TSetupStep);
    begin
      if CurStep = ssPostInstall then
      begin
        if Exec(
             ExpandConstant('{app}\{#MyAppExeName}'), '', '', SW_SHOW,
             ewWaitUntilTerminated, ExitCode) then
        begin
          Log(Format('Command finished, exit code is %d', [ExitCode]));
        end
          else
        begin
          Log('Failed to run command');
        end;
      end;
    end;
    
    function GetCustomSetupExitCode: Integer;
    begin
      if ExitCode <> 0 then
      begin
        Log(Format('Returning exit code %d', [ExitCode]));
      end;
      Result := ExitCode;
    end;
    

    请注意,Windows 进程退出代码不能为负数。退出代码是一个无符号的 32 位整数。

    查看ExitProcessuExitCode 参数和GetExitCodeProcesslpExitCode 参数如何分别属于UINTDWORD 类型。

    退出代码被解释为已签名只是一个常见的错误/误解。

    Inno 设置通过在 GetCustomSetupExitCode 中使用有符号整数值来遵循这种误解。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-13
      • 1970-01-01
      • 2016-04-29
      • 2016-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多