如何在Inno Setup中从Execute File的返回码设置退出代码?

时间:2015-12-11 03:16:12

标签: inno-setup exit-code

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

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

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

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

如何更改[Run]&我的目标是[Code]部分?

请帮帮我,给我示例代码

由于

BR, 艾伦

1 个答案:

答案 0 :(得分: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 Setup通过在GetCustomSetupExitCode中使用有符号整数值来遵循这种误解。

相关问题