23

Is it possible to run a file with Inno Setup, before the setup beginns? Documentation

Amicable
  • 3,115
  • 3
  • 49
  • 77
Stephan Schielke
  • 2,744
  • 7
  • 34
  • 40

2 Answers2

29

Yes it is. In the [code] section run the file in the InitializeSetup() function. This example launches notepad before the setup runs.

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

  // Launch Notepad and wait for it to terminate
  if Exec(ExpandConstant('{win}\notepad.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;
mghie
  • 32,028
  • 6
  • 87
  • 129
Jan Derk
  • 2,552
  • 27
  • 22
  • 26
    This should not be done in InitializeSetup if it changes anything on the users computer. This should be done after the user has pressed "Install", i.e. PrepareToInstall() or CurStepChanged(ssInstall). – Deanna Jul 25 '11 at 15:44
1
[Code]
function PrepareToInstall(var NeedsRestart: Boolean): String;
var
   ResultCode: integer;
begin
   ExtractTemporaryFile('卸载.bat');
   if Exec(ExpandConstant('{tmp}\卸载.bat'), '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then
   begin
   end
   else begin
   end;
   
end;

detail image