1
votes

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?

2
I copy/pasted my app to Desktop and when I use this : 'C:\Users\Oceanjack\Desktop\Injector.exe', it doesn't work.Ali Avcı

2 Answers

3
votes

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.

1
votes

This May work for you... I believe that this problem is because of spaces in the entire path..that should overcome with double quoting the path...

Exec('cmd.exe','/c "'+ExpandConstant('{src}\MyFolder\Injector.exe')+'"', '',SW_SHOW,ewWaitUntilTerminated, ResultCode);

cheers..