如何在 Inno Setup 中从我的执行文件的 return 代码设置退出代码?

How can I set the exit code from return code of my Execute File in Inno Setup?

我想从我的 {app}\{#MyAppExeName} 中获取 return 代码(负值)用于设置退出代码(MyAppExeName 将 运行 20~30 秒)

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

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

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

如何针对我的目标更改 [Run][Code] 部分?

请帮助我并提供示例代码

谢谢

BR, 艾伦

到 运行 一个外部进程并使用 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 位整数。

看看ExitProcess and well as lpExitCode parameter of GetExitCodeProcessuExitCode参数分别是UINTDWORD类型

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

Inno Setup 通过在 GetCustomSetupExitCode.

中使用有符号整数值来遵循这种误解