Using Process Exit code to show error message for a specific File in [Run]

Using innosetup and want to show error/msgbox if one of the [RUN] process does not return process code 0. I'm using it for authorization process, if authorization is not successful, i want to notify the user.

I have following:

Filename: "{pf32}\Common Files\Authorization.exe"; Parameters: " "{code:GetAuthorizationFilePath}" /s"; WorkingDir: "{tmp}"; Flags: skipifdoesntexist hidewizard; StatusMsg: "Authorizing License"; 

Returns me:

Process exit code:0

0 of course is successful, but if its not 0 i want to notify the user.

Is there a way to do that?

Thanks and Regards, Kev84


I think there's no way to accomplish this from the [Run] section. What you can do is:

  • use the Pascal Script for this task
  • or display the modal error message from your executed application Authorization.exe and terminate it only after the user confirms the error message (setup will then continue e.g. with the execution of the other files in the [Run] section)

Here is the code sample of the Pascal Script; you can check also the commented version of this code:

[Code]

function NextButtonClick(CurPageID: Integer): Boolean;
var
  ResultCode: Integer;
begin
  Result := True;

  if CurPageID = wpWelcome then
  begin
    Result := False;
    if Exec(ExpandConstant('{pf32}\Common Files\Authorization.exe'), '', '', 
      SW_SHOW, ewWaitUntilTerminated, ResultCode) then
    begin
      if ResultCode = 0 then    
        Result := True
      else
        MsgBox('The authorization failed!', mbCriticalError, MB_OK);
    end;
  end;
end;

I had the same requirements: to run an external program and display an error message if the return code is not 0. It was very important for me to run the program in the Run section as I needed to display a status message and the progress bar is nice to have.

I found that you can use AfterInstall in the Run section to trigger the execution of your program and check the result code (see this link for more info about AfterInstall.)

So, my idea was to run a dummy program like change and to use the procedure specified in AfterInstall to run the real program and catch its result code.

[Code]
procedure ExecuteRealProgram();
var
    ResultCode: Integer;
begin
    if Exec(ExpandConstant('{pf32}\Common Files\Authorization.exe'), '', '', SW_SHOW,
            ewWaitUntilTerminated, ResultCode)
    then begin
        if not (ResultCode = 0) then
            MsgBox('Error! ResultCode is ' + IntToStr(ResultCode), mbCriticalError, MB_OK);
    end
    else
        MsgBox('Exec failed! Error: ' + SysErrorMessage(ResultCode), mbCriticalError, MB_OK);
    end;
end;
[Run]
Filename: "change.exe"; WorkingDir: "{tmp}"; \
   StatusMsg: "Running external program. Please wait.";  AfterInstall: ExecuteRealProgram