Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inno Setup Execute a batch file before [Files] section

Currently my batch file is in [Run] section. I need my batch file to execute before the [Files] section. Is there a way to do this in Inno Setup? Currently the [Run] section always execute after [Files] section.

[Run]
Filename: "C:\Users\Scripts\Install\Install.bat"; Parameters: {code:GetDatabaseName}  

[Files]
Source: "C:\Users\MyApp\*"; DestDir: "\\MyServer\MyApp"; Flags: recursesubdirs createallsubdirs
like image 909
odez213 Avatar asked Jul 25 '11 14:07

odez213


2 Answers

If it needs to be done at the beginning of the setup, use Exec() in the PrepareToInstall() or CurStepChanged(ssInstall) event functions. These are both after the user has said "go ahead, install" but before anything else. PrepareToInstall() also allows you to cancel the install with a nice warning.

If the file needs to be extracted from the setup first, then you can preceed it with ExtractTemporaryFile()

like image 144
Deanna Avatar answered Oct 27 '22 11:10

Deanna


Continuing Deanna's great answer, code example:

[code]
function PrepareToInstall(var NeedsRestart: Boolean): String;
var
   ResultCode: integer;
begin
   Exec(ExpandConstant('{app}\serviceDeployment\unInstallService.bat'), '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode)
end;

this code always returns an empty string, which tells the setup to continue. In case you want to stop setup (in some error cases) you need to return a non empty string and it will be displayed to the user (and setup will be stopped).

In order to return an error string add this line in PrepareToInstall's:

Result := 'Your Error Description';
like image 38
Danielle Avatar answered Oct 27 '22 13:10

Danielle