PDA

View Full Version : Uninstall cleanup of HKEY_USERS



marc.gibian
08-24-2005, 06:47 PM
I am working on the setup for an existing application. This application generates runtime entries in HKEY_CURRENT_USER. I have now been asked to add functionality to the setup for this application to delete these keys for all of the users on the machine from which the application is being uninstalled. I do not see any mechanism that allows me to find all of the top level keys in the KEY_USERS hive, and thus I don't see how I can implement this task without writing a helper program... something I'd really prefer to avoid for such an installation specific task.

Does anyone out there have any ideas regarding how I delete all instances of this application's key from HKEY_USERS? Other than the user-specific GUID I know the path to this key, but without a way to iterate through all of the top level keys in this hive, I don't see a solution?

davech66
08-25-2005, 10:10 AM
I think you can use VBScript as custom function to delte it. Using script you can search for the top level key if you do not know which one it is, then you can use RegDelete.
Hope this helps.

marc.gibian
10-12-2005, 06:02 PM
I've been working a great deal with InstallScript since I originally posted my question. I am now well-versed enough to be able to ask some follow ups:

1 - Can I access the same objects from InstallScript that you would use via VBScript to search the HKEY_USER tree of the registry for keys of interest to my product?

2 - If I can't do this with InstallScript, it seems like the next simplest thing to do would be to write a C# dll containing the functionality I need, since the .NET Registry support is quite good. But, I keep having problems invoking C# from within my installs?

3 - If I can't do this easily, next is simply falling back to good ole C++ since I've already proven I can call into a C++ DLL. Of course, the simplest thing is to then have my C++ used the Managed Extensions and the .NET Registry Classes to do what I want.

Christopher Painter
10-12-2005, 08:59 PM
I've had to do this and I can tell you it's not as simple as walking all the SID keys under HKEY_USERS. You have to realize that Windows doesn't load all the user profiles all the time. Windows has a registry key that keeps track of profiles and when the user logs on his ntuser.dat hive is loaded into HKEY_USERS.

In the past I wrote an EXE that took the name of a registry key to delete. The EXE then walked all the user profiles, loaded the hive, deleted the key and unloaded the hive if it wasn't already loaded.

Just a few things to think about. This is something that I wish WindowsInstaller handled natively.

Christopher Painter
10-12-2005, 09:03 PM
1 - Can I access the same objects from InstallScript that you would use via VBScript to search the HKEY_USER tree of the registry for keys of interest to my product?


VBScript and InstallScript both support CreateObject(). VBScipt supports collection enumeration, InstallScript does not natively, but there are some intersting ways to make it. InstallScript also supports Win32 API calls like VB6 where VBScript does not.



2 - If I can't do this with InstallScript, it seems like the next simplest thing to do would be to write a C# dll containing the functionality I need, since the .NET Registry support is quite good. But, I keep having problems invoking C# from within my installs?


The trick is to do COM Interop from your C# and get it registered so you can create the object from within your CA. This is a bit of a chicken and an egg problem if you want to call the object with immediate context prior to the installation transaction but it can be done.



3 - If I can't do this easily, next is simply falling back to good ole C++ since I've already proven I can call into a C++ DLL. Of course, the simplest thing is to then have my C++ used the Managed Extensions and the .NET Registry Classes to do what I want.

C++ MSI DLL's are very nice if you are quick at programming in C++. The previous post I taked about loading registry hives, thats all Win32 API which is done easily from C++.

Christopher Painter
10-12-2005, 09:03 PM
1 - Can I access the same objects from InstallScript that you would use via VBScript to search the HKEY_USER tree of the registry for keys of interest to my product?


VBScript and InstallScript both support CreateObject(). VBScipt supports collection enumeration, InstallScript does not natively, but there are some intersting ways to make it. InstallScript also supports Win32 API calls like VB6 where VBScript does not.



2 - If I can't do this with InstallScript, it seems like the next simplest thing to do would be to write a C# dll containing the functionality I need, since the .NET Registry support is quite good. But, I keep having problems invoking C# from within my installs?


The trick is to do COM Interop from your C# and get it registered so you can create the object from within your CA. This is a bit of a chicken and an egg problem if you want to call the object with immediate context prior to the installation transaction but it can be done.



3 - If I can't do this easily, next is simply falling back to good ole C++ since I've already proven I can call into a C++ DLL. Of course, the simplest thing is to then have my C++ used the Managed Extensions and the .NET Registry Classes to do what I want.

C++ MSI DLL's are very nice if you are quick at programming in C++. The previous post I taked about loading registry hives, thats all Win32 API which is done easily from C++.