Launch file from package
The following article uses options that are available starting with the Professional edition and project type.
It is common to encounter situations where you need to launch a file from the package during the installation or uninstallation process. Whether the file is an .EXE, .BAT, or any other file type, these samples will provide all the necessary steps.
In the current sample, we will demonstrate how to configure the setup package to launch a file during both the installation and uninstallation processes.
1. Create project
After launching Advanced Installer, you will be presented with a dialog where you can choose the type of the project you want to create.
Select Professional and press the Create Project button. The new project has been created and from now on you will edit it.
Save the project and give it an appropriate name - let's say "Launch File
Sample" for this example.
2. Enter product details
Now you can see the main view split into two panes. In the left pane, you can see all the options you have to edit in your current project, grouped in categories.
Switch to “Product
Details” page to set the information seen by the user for your installation
package. Fill the fields in the right pane with the corresponding data.
The information from this view will be displayed in the Control Panel.
3. Add files and folders to your project
The next step is to add to the project the files and/or folders that compose your application.
Select “Files and Folders” from the
“Resources” menu on the left pane.
Click on the toolbar button and select the files
of your application, or use the drag-and-drop to add resources from
the disk to the project. In our case, the EXE file is a text editor which will be launched
during the install process.
Let's assume that we also need to launch a file that should not be installed on the end-user machine e.g. that file is only required to be launched during the installation.
For this scenario, you can add that file as a temporary file.
Temporary files also allows us to launch a file earlier during the install proces,
before files are actually copied on the target machine. This is happening because
Temporary Files are copied between the
CostFinalize and MigrateFeatureStates standard actions,
at the beginning of the setup and removed during the InstallFinalize
standard action.
In order to easily recognize them they have the following icon:
Use the toolbar button,
the “Add Temporary Files...” tree/list context menu item. You can add more than
one file at a time. If a file with the same name already exists in the target directory, the
file to be added is skipped.
Here's how the file looks like in the project after it was added as temporary file:
Once you’ve added the files of your application in the Files and Folders view, we we can configure the setup to launch the files from the package.
4. Configure custom action
To launch a file during the installation, you can use a custom action. Switch to the Custom Actions view to configure the custom actions that will launch files during installation.
4.1 Launch regular file
Let's assume that we need to launch our Text Editor EXE file during the installation but also during the uninstall process.
To launch a file from the package, you can use the predefined Launch file custom action. Add this custom action as a custom action with sequence.
Once the file has been added, configure it as below:
Important aspects to consider for the custom action properties.
When the custom action reference any file installed by the setup, the custom action needs to be executed after the files are copied on the target machine. That means the custom action should be placed after the Add Resources action group.
Also, the custom action needs to be executed when the system is being modified (deferred). This is happening because the files are copied on the machine during the deferred phase. You can read more about the execution time of a custom action in the Setting execution time for custom actions article.
If the execution requires admin privileges then the Run under the LocalSystem account with full privileges (no impersonation) option needs to be selected. Most of the time this option should be enabled.
Always disable the Uninstall execution time.
Custom actions that are executable files must return a value of 0 for
success. The installer interprets any other return value as failure.
Add another predefined Launch file custom action with sequence to launch the file during the uninstall. The custom action that is configured for the Uninstall process needs to be executed before Remove Resources action group. This is required because after the Remove Resources action group, the files installed by the pacakge are no longer available, they were removed from the disk.
Here's how the custom action can be configured:
If the custom action does not require admin privileges, then we can keep the Immediately execution time.
If the custom action requires admin privileges, the custom action needs to be executed when the system is being modified (deferred) so that we can enable the Run under the LocalSystem account with full privileges (no impersonation) option.
4.2 Launch temporary file
You may choose to add the file as a temporary file and execute it as a temp file, mostly in the following cases:
- The file that is being executed should not be deployed on the end-user machine
- The file is required to be executed earlier during the installation, before the regular files being available.
Add another predefined Launch file custom action with sequence to launch the temporary file during the installation. The temporary custom action can be executed before Add Resources action group.
Here's how the custom action can be configured:
As mentioned before, the file added as a temporary file is not being installed on the end-user machine, it is only available during the installation.
5. Build and install
When running the current sample, a .txt file will automatically launch immediately after the installation begins, even before any dialog appears.
Once the installation continues, there will be another file launched, the Text Editor. The same Text Editor will be launched when removing the setup from Control Panel.