Abort installation based on a custom scenario
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 abort installation if certain conditions are not met on the machine where the setup is running.
In the current sample we'll present how you can use the result of a search operation and the result of a custom action to prevent the user from installing the application.
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 "Abort
Installation 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. Prevent installation based on the result of a search operation or of a custom action
Sometimes, the predefined search options will meet your requirements. However, if these are not sufficient, you can always extend the installer functionality using custom actions.
3.1 Add Registry Search
Let's say that we want to prevent the installation if a certain registry is not found on the machine. For this, we can add a registry search operation in the Search view.
Lets use the [ New Search Wizard ] toolbar button to define a new search following step-by-step directions.
Let's search for the following registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Caphyon\PacKit
If the above registry is not present, then the installation should abort.
This is how the search properties look like:
We also have the option to test the search as the setup would run on our machine:
Because the registry is present on my machine, the installation should be successful, showing the install location for PacKit. Retrieving the installation path for a software is crucial. For instance, you may need this information to install a specific add-in, update a configuration file, or load an extension that is part of the software installation.
Beside the possibility to add your custom search, Advanced Installer comes with a
predefined list of Extended Search which you may find useful, based
on your scenario.
3.2 Create custom action
Sometimes, the predefined searches operations that can be configured with the installer still does not cover all custom scenarios.
If you need further customization of your particular scenario, then you can use a custom action. Let's use a PowerShell Script custom action to search for the very same registry key. Here's how the powershell code looks like that checks the presence of the related registry:
# Define the registry path $registryPath = "HKLM:\SOFTWARE\Caphyon\PacKit" # Check if the registry path exists if (Test-Path $registryPath) { # Get the Path value $pathValue = Get-ItemProperty -Path $registryPath -Name "Path" -ErrorAction Stop | Select-Object -ExpandProperty Path # Output the Path value Write-Output "Path value: $pathValue" # Set MSI Property with Path value AI_SetMsiProperty PACKIT_PATH $pathValue } else { Write-Output "The registry path '$registryPath' does not exist." # Reset PACKIT_PATH property if the registry does not exist AI_SetMsiProperty PACKIT_PATH "" }
This is how the custom action looks like in the project:
Make sure the PowerShell custom action runs
before Paths Resolution action group, so that the custom action is executed
before the launch conditions evaluation.
You can share the custom action between the Wizards Dialogs Stage and the other in the Install Execution Stage. Simply drag a custom action from one stage to the other, while pressing the Shift key. This is useful to ensure the custom action gets executed during a silent installation.
Advanced Installer provides predefined support for integrating custom actions and
supports a wide range of custom actions written in C++, .NET, DTF C# or scripting languages such as PowerShell.
Check the How to set windows installer properties using custom actions article to see how you can set and access installer properties within the custom action.
4. Prevent installation using a custom launch conditions
So far we've added the support in the installer to search for the related registry key either using the predefined search or through a custom action when we have a more particular scenario.
Let's configure the installer to abort installation if the registry key is not found on the machine. In the custom launch conditions tab you can define the launch conditions to prevent the installation in case the registry is not found on the machine:
The condition will be evaluated to false if the property attached to the search operation is empty e.g. the registry does not exist.
Explore the predefined System Launch
Conditions and Software Launch
Conditions that Advanced Installer comes with. They may cover already your
scenario.
5. Build and install
If you build and run the package on a machine where the Packit software is not installed, the launch condition will be fired preventing from installing the software: