相关文章推荐
温文尔雅的卡布奇诺  ·  Spring LDAP Reference·  10 月前    · 
安静的豆浆  ·  string - ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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

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()

ResultCode: integer; begin Exec(ExpandConstant('{app}\serviceDeployment\unInstallService.bat'), '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode)

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';
                Well, then would be fair to show how to handle error when Exec fails, or when the executed target returns an error (in this case a batch script returning certain ERRORLEVEL).
– TLama
                Feb 25, 2015 at 11:47
                Exec is boolean. so you can check whether it true or false. and ResultCode contains the error code.         if not Exec(.........) then         begin             Result := 'Your Error Description';          end
– Danielle
                Feb 25, 2015 at 12:22

You can use the InitializeSetup event + some pascal scripting.

See; How to run a file before setup with Inno Setup

Not mentioned in that example; to get the file from the installer you would use ExtractTemporaryFile('your.bat') then Exec(ExpandConstant('{tmp}\your.bat ... to run it.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.