Catalin
Posts: 6509
Joined: Wed Jun 13, 2018 7:49 am

Prerequisite install detection criteria - How to create one

Tue Oct 12, 2021 4:47 pm

Hello guys,

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
Note: The above explanation will make much more sense as we will get to work on an example.

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

Hands-on example:

Let's consider we want our setup to install "Notepad++" as a prerequisite.

The first question we should ask ourselves here is:
How can I uniquely identify if Notepad++ is already installed on the machine?
As I've mentioned earlier, we might find the answer in the registry.

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++
In my case, I have installed a 32-bit version of Notepad++ on my 64-bit machine, therefore the location I am looking in is the following:

Code: Select all

HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node
Here is how that looks on my machine:
NotepadRegistry.png
NotepadRegistry.png (84.08KiB)Viewed 259450 times

As we can see, we are pretty lucky because we already found a key related to "Notepad++".

The key contains the following entry:
KeyContent.png
KeyContent.png (6KiB)Viewed 259450 times
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:
AfterUninstallNotepad.png
AfterUninstallNotepad.png (77.76KiB)Viewed 259450 times

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
InstallBasedOnConditions.png
InstallBasedOnConditions.png (60.67KiB)Viewed 259450 times

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
SelectKey.png
SelectKey.png (44.48KiB)Viewed 259450 times

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:
Is64bit.png
Is64bit.png (11.16KiB)Viewed 259450 times

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.
Notepad++Installation.png
Notepad++Installation.png (135.19KiB)Viewed 259450 times


Hope this article helped clearing the "mistery fog" surrounding the detection criteria of a custom prerequisite! :)

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Sample Projects”