The most often item left behind upon the uninstall of an application is registry keys. So how do we ensure that our uninstalls are clean?
This can range anywhere from a minor nuisance to a major problem. I had just uninstalled a particular application I was using because the upgrade instructions had told me to do so. Upon attempting to install the new version, I received an error message telling me to uninstall the previous version prior to installing the new version. Being prone to fits of senility, I decided to double-check that I had indeed removed the old version. My brain had not failed, I did and there was no trace in Add/Remove Programs. I looked in the Program Files directory and nothing was to be found there either.
Rather than go on a Snipe hunt in the registry, I employed the usage of a couple of handy tools from Mark Russinovich (
http://www.sysinternals.com/index.html). The installer was checking a registry key to see if it existed on the machine. This is how the installer was determining if a previous version of the application was installed. They were checking a registry that they don't remove with their uninstall. Brilliant…
Now this particular application didn't use Windows Installer for the install and they hadn't read the tips I was about to give you, so I won't fault them too much. Prior to the introduction of Windows Installer, it was actually very common to find applications leaving registry keys behind on uninstall. The application usually generates them leaving the installer unaware they exist. Some extra logic would have to have been placed in the uninstall routine to handle such a situation.
Windows Installer by default, will remove any registry keys that it installs. However, you have the same problem you had with legacy installations, they don't get removed if they were created by the application. You need to tell Windows Installer which registry keys to remove. One would automatically assume that they would need to start populating the RemoveRegistry table (
http://msdn.microsoft.com/library/en-us/msi/setup/removeregistry_table.asp) in order to ensure that the registry keys are removed when an application is uninstalled. Make sure you look very closely at the remarks for the RemoveRegistry table in the SDK.
"The registry information is deleted from the system registry when the corresponding component has been selected to be installed locally or run from source."
Hmmm... That is not going to be very helpful. The RemoveRegistry table will only remove registry keys when a component is installed locally or run from source, not when a component is being removed. In order to remove registry keys when a component is removed, we'll need to take a look at the Registry table (
http://msdn.microsoft.com/library/en-us/msi/setup/registry_table.asp).
Look at the information listed for the Name column. In there it indicates that is a - sign is in the name column that the "key is to be deleted, if present, with all of its values and subkeys, when the component is uninstalled." Now it looks like we are getting somewhere. I need you to be aware though,
ALL of the values and subkeys will be removed. This is not a selective removal. If you want to do a selective removal, you will need to use a custom action.
In order to populate the registry table, it will look something like this:
| RemoveReg001 | 2 | Software\My Application\Test | - | {NULL} | RemoveRegistry |
RemoveReg001 is the key for this entry in the registry table or the Registry column.
2 defines the Root column which is HKEY_LOCAL_MACHINE.
Software\My Application\Test is the registry key which occupies the Key column. The
- symbol in the Name column is what tells Windows Installer to remove all the values and subkeys during an uninstall. The Value column is left blank and the last column is the component to which this registry key belongs. In this case, it is a component called
RemoveRegistry.
I hope this will help make for cleaner uninstalls. If anyone has suggestions or requests on topics you would like to hear about, please send me an email. I am more than happy to come up with this stuff on my own, but please let me know. I was thinking about writing on patches and upgrades next. Let me know...