How to detect and use return code from application

704 views
Skip to first unread message

Majkl

unread,
Apr 29, 2021, 2:14:17 AM4/29/21
to innosetup
Is here some way how to detect return code from application running in [run] section?

[run]
Filename: "{app}\prg.exe"; 
....
if (retcode = 0)
...stop installation...


Thanks for help.

Gavin Lambert

unread,
Apr 29, 2021, 2:38:30 AM4/29/21
to inno...@googlegroups.com
No, that is not possible. [Run] ignores exit codes, and even if it
didn't, they're run too late to actually stop the installation. (Also,
exit code 0 usually means success, not an error...)

If you want to do something with exit codes, you will need to use [Code]
instead of [Run].

If you want to stop the installation, then that [Code] should probably
be in the PrepareToInstall function. Note that this is called before
anything is actually installed, so you will need to use
ExtractTemporaryFile(s) to extract the minimum files needed to run the tool.

Alternatively, it may be simpler to write a DLL and call it from
PrepareToInstall; Inno handles the extraction for you in this case, and
you can more easily communicate with the install script.

Majkl

unread,
Apr 30, 2021, 4:17:55 AM4/30/21
to innosetup
OK thanks for answer. 
Code - it means code in Pascal, is not it?
And maybe is here easier way - has not IS any builtin function to detect, if some process is run?
(I provide plug-in for Autocad and in case of unistalled process I need to have Acad.exe closed)

Thanks

Dne čtvrtek 29. dubna 2021 v 8:38:30 UTC+2 uživatel Gavin Lambert napsal:

Sebastian P.R. Gingter

unread,
Apr 30, 2021, 4:36:02 AM4/30/21
to innosetup
Hello Majkl,

I did that with an AfterInstall script for the .exe. Put it as afterInstall: AfterInstallMyComponentsExe; in the [Files] line for your exe.
Don't use a * for a folder, as AfterInstall will be called for every single file in it. So I have a separate line for the .exe to call only in [Files].

procedure AfterInstallMyComponentsExe;
var
    fileName: String;
    returnCode: Integer;
begin
    // Call the exe:
    fileName := ExpandConstant(CurrentFileName()); // This gets the name to your exe
    Exec(fileName, '', '', SW_HIDE, ewWaitUntilTerminated,  returnCode  ); // the second parameter are additional cmdline params for your exe

    // here you'll have the return code in the variable
    // in my case, the manual states that if it returns "2" a reboot is requested:
    RequireRestart := RequireRestart or (returnCode = 2);
end;


Reply all
Reply to author
Forward
0 new messages