Monday, February 13, 2012

Inno Setup, Part 2. Running files during installation and uninstallation.

One of the common tasks during installation is to copy file to some temp directory, run it and delete after that. For example, it can be some script. In our example we are creating database necessary for our application work. First part is copying the file to temp directory, this is done in [Files] section:

Note deleteafterinstall flag, it indicates the file will be deleted at the end of installation when it won’t be necessary any longer.
The second part is to launch this file at the end of installation process (of course, this takes place before deleting of the files, Inno Setup handles this correctly automatically):

[Run]
Filename: {tmp}\CreateDatabase.bat; Flags: runhidden;

Note runhidden flag here, it indicates that this operation won’t be visible for users of your installer. This flag can be removed if you prefer to leave this operation noticeable.
When your application is uninstalled, you may need also to launch a file. In our example, we need to delete database.

We are using the same flag runhidden, but now we can’t use temporary directory, we need to run from application directory or from some folder like commonappdata. The file needed for deleting database was created during process of installation in [Files] section: