how to remove hkcu keys using MSI after uninstallation of a product?,
Answers (4)
Active setup uses HKLM\software\microsoft\Active Setup\Installed Components\Name_or_id to uniqually identify the instance. If you use the MSI's GUID as the name_or_id part it will be globally unique. When a user logs in the HKLM part is compared with the value in HKCU and if it doesn't exist Active Setup runs whatever is in StubPath and then sets the HKCU key so it doesn't happen again.
If you uninstall the msi that wrote the HKLM part of the active setup then it won't run for any users after the uninstall as the HKLM part won't exist. If you re-install that same msi but increment the version value in the active setup key then it will run again for each user. The format for the version key is Version = a,b,c,d. Usually you start with version set to 1,0,0,0, then you can use 1,0,0,1 or 2,0,0,0 depending on how you want to do it. So long as you increment it on each version of your msi then it will always run for each user.
Refer this link to understand more :
http://www.sepago.de/helge/2010/04/22/active-setup-explained/
Also it is very important to add a custom action that runs during uninstall. This custom action should increment the value of "Version". For your reference use this script:
VBScript Code:
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Option Explicit
On Error Resume Next
Dim objShell,intVersion
Set objShell = CreateObject("WScript.Shell")
intVersion = objShell.RegRead("HKLM\SOFTWARE\Microsoft\Active Setup\Installed Components\{ProductCode}\Version")
intVersion = intVersion + 1
objShell.RegWrite "HKLM\SOFTWARE\Microsoft\Active Setup\Installed Components\{ProductCode}\Version", intVersion , "REG_SZ"
Set objShell = Nothing
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
HKCU and ActiveSetup is an interesting challenge. Keep in mind that these keys exist for everyone who has logged in since the application was installed. There are really 2 ways to deal with this: load every user reg hive and delete the keys, or increment the ActiveSetup version to run if there's a reinstall. Both have challenges - dealing with locked hives or hives that don't unload, and having someone log in after the uninstall and trying to run the ActiveSetup are the first 2 that come to mind.
Comments:
-
Oops, submitted too quickly. My client, who puts everything in a WinBatch wrapper, had me write a function that loads all the registry hives and delete the keys. In the strictest way of thinking, that would make sense as the best way to deal with ActiveSetup. - Arminius 12 years ago