Active Setup and Per-User/Per-Machine registry

The Windows Installer allows you to create a setup which will dynamically writes registry keys into either  HKCU or HKLM. This behaviour is then controlled by the “ALLUSERS” Property.

The Windows Installer Help describes this feature as follow:

 Constant  Hexadecimal  Decimal  Root key
 (none)  – 0x001  -1  If this is a per-user installation, the registry value is written under HKEY_CURRENT_USER.If this is a per-machine installation, the registry value is written under HKEY_LOCAL_MACHINE. Note that a per-machine installation is specified by setting the ALLUSERS property to 1.

We will now provide an example to illustrate this behaviour:

reg01

 

In this MSI I have chosen the “AppDataFolder” system property as Value  in order to check the resolved path. The path will be different for each user because its an per-user defined system property.

If you install this key with the ALLUSERS Property set to “1” the result will be as following:

[HKEY_LOCAL_MACHINE\SOFTWARE\Ontrex\Example]
"UserOrMachine"="C:\Users\Administrator\AppData\Roaming\"

The key will be installed into HKLM however the property will be resolved according to the current installing user.

If you install this application again with ALLUSER set to “2”  the result will look like this:

[HKEY_CURRENT_USER\Software\Ontrex\Example]
"UserOrMachine"="C:\Users\test\AppData\Roaming\"

More details about this behaviour/feature can be obtained from the following MSDN Article:

http://blogs.msdn.com/b/windows_installer_team/archive/2009/09/02/authoring-a-single-package-for-per-user-or-per-machine-installation-context-in-windows-7.aspx

Conclusion: The registry root parameter can be used to dynamically write the registry keys into HKCU or HKLM  based on the current installation context (Per-User <> Per-Machine)

But what happens if you have a per machine installation which contains an active setup mechanism?

Let’s have a deeper look into it:

We add all corresponding registry keys, features and components to the MSI  which are required  for a fully functional Active Setup.

Now let’s install the MSI under system account with ALLUSER=1 and check the example registry key.

The Result is:

[HKEY_LOCAL_MACHINE\SOFTWARE\Ontrex\Example]
"UserOrMachine"="C:\Windows\system32\config\systemprofile\AppData\Roaming\"

Now log off and log on with a standard user account and check the key again and something unexpected happened. As you see the key changed to:

[HKEY_LOCAL_MACHINE\SOFTWARE\Ontrex\Example]
"UserOrMachine"="C:\Users\test\AppData\Roaming\"

What happend?

The Property ALLUSERS sets the installation to a  machine installation and the Active Setup will be execute with the following option “/fu” (all required user-specific registry entries).

Answer:
During the active setup the windows installer will repair the MSI in User Context and only user-specific registry keys will be rewritten (“/fu” parameter). All “-1” however are simply considered as “user based keys” even the ALLUSERS property is set to “1”. Because the repair works with elevated priviliges this HKLM key will now be rewritten using the current users [AppDataFolder] value.

Our conclusion

We will kindly advice you not to use “-1” in the root column of the Registry table in a windows installer database in conjunction with active setup. Also bear that in mind when you are adding activesetup to an existing vendor msi (Transform).

Regards,

SPA Team

Comments are closed.

Post Navigation