In today's article, we are gonna discuss how to create a detection criteria for a custom prerequisite.
Although Advanced Installer offers a generous list of predefined prerequisites (such as .NET Framework, Visual C++ Redistributable and so on), there might be cases where one might need to add a custom prerequisite to his setup package.
When this situation arises, we would like to carefully condition that prerequisite to only be installed if not already present on the machine.
First of all, let's discuss what a "detection criteria" is and how your setup package will use it to determine whether the prerequisite should be installed or not.
Definition: A "detection criteria" is a unique condition (or a set of unique conditions) that has to be met in order for your prerequisite to be installed.
Here, there are two scenarios that need to be taken into consideration:
1. "Prerequisites" page --> your prerequisite --> "Setup Files" tab --> "Continue with the main installation even if prerequisite is not installed" option is checked.
In this scenario, the detection criteria will be evaluated only once, before the prerequisite is installed and the condition must be evaluated as false.
2. "Prerequisites" page --> your prerequisite --> "Setup Files" tab --> "Continue with the main installation even if prerequisite is not installed" option is unchecked.
In this scenario, the detection criteria will be evaluated twice:
- once before the prerequisite is installed and the condition must be evaluated as false
- once after the prerequisite is installed and the condition must be evaluated as true
One good detection criteria we can use here is a "registry search", because we all know that pretty much every setup package will write some information in the registry (such as the installed version, the installation path, etc.).
Let's consider we want our setup to install "Notepad++" as a prerequisite.
The first question we should ask ourselves here is:
As I've mentioned earlier, we might find the answer in the registry.How can I uniquely identify if Notepad++ is already installed on the machine?
Here would be the steps we need to take in order to find out if the above is true:
- on a clean machine (e.g. a Virtual Machine), manually install Notepad++
- open the Registry Editor (regedit.exe) and look for a key that might be related to Notepadd++
Here is how that looks on my machine:
Code: Select all
As we can see, we are pretty lucky because we already found a key related to "Notepad++".
The key contains the following entry:
That looks to be the installation folder of Notepad++.
As we can see, this key is unique to Notepad++ and is present on the machine only if the product is installed.
If we uninstall Notepad++ and refresh the Registry Editor, we can see that the key is no longer there:
Therefore, this key checks both our requirements:
a) is unique
b) helps us determine whether Notepad++ is installed or not
Now, let's try to implement the above in Advanced Installer. To do so, please follow the below steps:
1. reinstall Notepad++ on the machine (this will come in handy later on)
2. open Advanced Installer and create a new project
3. go to "Prerequisites" page and add "Notepad++" as a "feature-based" prerequisite
4. select the prerequisite and go to "Install Conditions" tab
5. under "Install Conditions", please select the "Install prerequisite based on conditions" option
6. click the "New..." button. This should open the "New search" dialog
7. if you expand the "Criteria" drop-down, we can see that there are a lot of searches we can perform
8. for our case, we could see above that the registry key "just existing" is enough, therefore please select the "Registry key exists" criteria
9. in the "Registry key" field, please click on the "..." button
Note: The reason why we reinstalled Notepad++ at point 1) is because now we can use the picker to select the key
Important note: If we pay close attention to the screenshot above, we can see something is missing (compared to the Registry Editor screenshot above) and that is the "WOW6432Node".
This has to do with the phenomenon called registry redirection. Basically, a 32-bit process looking in the registry will always be redirected under the WOW6432Node on a 64-bit machine.
In our case, the setup package is of 32-bit type ("Install Parameters" page --> "Package Type") and the machine is 64-bit:
and therefore the search will always be redirected under the WOW6432Node.
This is something really important that we need to take into account when developing a detection criteria for a custom prerequisite and it would be really nice to know beforehand.
To sum it all up, here are the configurations we are using in our example:
- 64-bit machine
- 32-bit prerequisite
- 32-bit main setup
If you have a 32-bit main setup and a 64-bit prerequisite (that will not write its' settings under WOW6432Node), it would be useful to avoid the redirection by checking the "Use 64-bit location when evaluating condition on a 64-bit machine" option from under "Install Conditions" section.
10. after selecting the registry key, please click "Ok"
11. remove the default condition (i.e. the "File Version" one) by selecting it and pressing "Remove"
12. build the setup
Testing the setup
Let's now test the setup to see whether this is working or not.
With the Notepad++ already installed, please launch the earlier built setup. As you can see, Notepad++ will not be installed because the condition was evaluated as true (meaning that the Notepad++ is already installed on the machine).
Now please open Control Panel and remove both Notepad++ and your setup package and then relaunch the setup.
Now, you should be prompted to install Notepad++, because the registry key no longer exist, resulting in the condition being false.
Hope this article helped clearing the "mistery fog" surrounding the detection criteria of a custom prerequisite!