Abort installation based on a custom scenarioCopy link to this sectionLink to this section copied!

ImportantThe 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 projectCopy link to this sectionLink to this section copied!

After launching Advanced Installer, you will be presented with a dialog where you can choose the type of the project you want to create.

Start Page

Select Professional and press the Create Project button. The new project has been created and from now on you will edit it.

SaveSave the project and give it an appropriate name - let's say "Abort Installation Sample" for this example.

2. Enter product detailsCopy link to this sectionLink to this section copied!

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.

Product DetailsSwitch 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.

Product Details

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 actionCopy link to this sectionLink to this section copied!

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.2 Create custom actionCopy link to this sectionLink to this section copied!

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:

Custom Actions Properties

ImportantMake 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.

NoteAdvanced 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 conditionsCopy link to this sectionLink to this section copied!

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:

Custom Launch Conditions

The condition will be evaluated to false if the property attached to the search operation is empty e.g. the registry does not exist.

ImportantExplore the predefined System Launch Conditions and Software Launch Conditions that Advanced Installer comes with. They may cover already your scenario.

5. Build and installCopy link to this sectionLink to this section copied!

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:

Custom Launch Conditions