0

I have followed this link to assign custom exitcode for the installer (.exe file)

I did this :

Method 1 : 

[Code]
procedure ExitProcess(exitCode:integer);
  external 'ExitProcess@kernel32.dll stdcall';


 var1 : = 10
 if (var1 <> 12) then //not equal to 12
 begin
 msgBox(<some message,mbInformation,MB_OK)
 ExitProcess(9)
 end;



 I have DOS shell script like this : 
    @echo off
    my_exe.exe /verysilent
    if %errorlevel% == 9 (
     echo Failure reason given is %errorlevel%
     exit /b %errorlevel%

    )

The output is : Failure reason given is 9



Method 2 : 

Now I used the following code :

function GetCustomSetupExitCode: Integer;
begin
  result := 9
end;

 var1 : = 10
 if (var1 <> 12) then //not equal to 12
 begin
 msgBox(<some message,mbInformation,MB_OK)
 // ExitProcess(9)
  GetCustomSetupExitCode();
 end;

I used the same DOS script In the output now I cant get the any exit code printed in the DOS.

Which way is correct.Is it safe to use ExitProcess()

Community
  • 1
  • 1
Raulp
  • 7,758
  • 20
  • 93
  • 155
  • On command prompt ? Do you mean something [`like this`](http://stackoverflow.com/questions/334879/how-do-i-get-the-application-exit-code-from-a-windows-command-line) ? If not, could you please elaborate where do you want to get that exit code ? – TLama Oct 28 '14 at 13:07
  • the exe will be run by a windows process ( may be startup script or a background process) .The installer may fail if there is an error(based on various conditions of ..for example condition X is met , etc).To test it I am running it on command prompt and want to know the error if any such condition is met.I deliberately generated a condition X and wanted to see the exit code by running it on command prompt.The link I share , i Have used it to assign the exit code but cant see it on console. – Raulp Oct 29 '14 at 05:01
  • 1
    Well, so then you need to do what is in the post I linked in my previous comment. Anyway, this question is not anyhow related to Inno Setup as it's about how to show the just executed application exit code. – TLama Oct 29 '14 at 09:30
  • Ok got it , in the post you linked in your previous comment => if errorlevel 1 , we can assign this exit code 1 in the innosetup so that it can be recognized as "1" by following the link I posted .We can assign the code using : ExitProcess(1) and print the code using errorlevel in the dos prompt .Thanks for the insight – Raulp Oct 29 '14 at 10:02
  • Do not use that `ExitProcess` way in your case. It is unecessarily *brutal* way. If you want to return a custom exit code, use the `GetCustomSetupExitCode` event (as said in the other answer). And I'm somehow lost from your last comment. Just execute the setup from command prompt and after the setup finishes get the exit code by writing e.g. `echo %errorlevel%` on that command prompt. That's all. What you return or what you execute doesn't matter since every process returns exit code (that's why I said this has nothing to do with Inno Setup). – TLama Oct 29 '14 at 10:18
  • Updated the Qs further.What i want is to catch the exit code on the dos prompt on the certain custom defined failed condition represented by my exit codes. – Raulp Oct 29 '14 at 11:04
  • You are not supposed to call `GetCustomSetupExitCode` function. It is called internally when the setup succeeds (which is the first condition that must be met to use custom exit code). – TLama Oct 29 '14 at 11:13
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/63861/discussion-between-raulp-and-tlama). – Raulp Oct 29 '14 at 11:25

0 Answers0