Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

inno-setup

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

like image 892
Kev84 Avatar asked Mar 08 '12 16:03

Kev84


People also ask

What is process exit code 1?

Exit Code 1 indicates that a container shut down, either because of an application failure or because the image pointed to an invalid file. In a Unix/Linux operating system, when an application terminates with Exit Code 1, the operating system ends the process using Signal 7, known as SIGHUP.

What do exit codes mean?

An exit code or exit status is a number that is returned by an executable to show whether it was successful. This is also sometimes called a return code, or in some cases, an error code, although the terminology here may be slightly different.


2 Answers

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;
like image 64
TLama Avatar answered Oct 16 '22 08:10

TLama


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
like image 33
Jason Avatar answered Oct 16 '22 07:10

Jason