Search code examples
inno-setuppascalscript

Inno Setup Script - running exe before installing


I wanna run an application before installing and I'm using this code on Inno Setup Script(Pascal):

function InitializeSetup():boolean;
var
  ResultCode: integer;
begin

 // Launch Notepad and wait for it to terminate
 if ExecAsOriginalUser('{src}\MyFolder\Injector.exe', '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then
 begin
// handle success if necessary; ResultCode contains the exit code
 end
 else begin
   // handle failure if necessary; ResultCode contains the error code
 end;

 // Proceed Setup
  Result := True;

end;

When I'm using "{win}\notepad.exe", It works but when I use "{src}\MyFolder\Injector.exe", Setup doesn't open my program and continues install.

Note : Injector has app.manifest which has 'requireAdministrator'. However this application should be run as administrator.

So what's wrong?


Solution

  • You need to use the ExpandConstant function when using values such as {src} in code.

    However, InitializeSetup is also too early to run installation tasks. You should move this code into CurStepChanged(ssInstall).

    Also, if it requires admin permissions it must be run with Exec, not ExecAsOriginalUser.