10

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

Kev84
  • 827
  • 3
  • 15
  • 26
  • See also [How to force Inno Setup setup to fail when Run command fails?](http://stackoverflow.com/q/1122588/850848) and [Inno Setup: How to Abort/Terminate Setup During Install?](http://stackoverflow.com/q/6345920/850848) – Martin Prikryl May 11 '17 at 13:11

2 Answers2

9

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;
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
TLama
  • 75,147
  • 17
  • 214
  • 392
  • So i have to create my own function in that [Run] Entry? If so where do I call that function? Is there a way to run the method after the process finishes, and if so how do i get the process/error code? – Kev84 Mar 08 '12 at 18:44
  • Sorry for being too late; I'm pretty sure you have resolved this by your own, but still... I've added the example of the PascalScript code along with the [`commented version`](http://stackoverflow.com/revisions/9621406/2). – TLama Apr 10 '12 at 12:15
  • 2
    If it replaces a `[Run]` entry, setting this code at `WpWelcome` doesn't seem like a good idea. Personally I'd use the `CurStepChanged` function, on `CurStep = ssPostInstall`. – Nyerguds Mar 27 '13 at 10:08
4

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
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Jason
  • 920
  • 8
  • 19