Stephan Schielke
Stephan Schielke

Reputation: 2853

How to run a file before setup with Inno Setup

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

Upvotes: 26

Views: 34462

Answers (2)

user18677603
user18677603

Reputation: 31

[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

Upvotes: 3

Jan Derk
Jan Derk

Reputation: 2980

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;

Upvotes: 32

Related Questions