PDA

View Full Version : Uninstall Reg Keys



sirhaden
11-03-2010, 11:41 AM
How should one go about creating an installation that does nothing to the registry during initial installation or maintenance, but deletes specified registry keys during uninstall?

The same functionality should work if the uninstall is invoked from the Control Panel or via the InstallShield installation file.

Holger_G
11-04-2010, 03:54 AM
Which project type do you use?
For Basic MSI you might take a look at the RemoveRegistry Table (http://msdn.microsoft.com/en-us/library/aa371208%28VS.85%29.aspx).

sirhaden
11-04-2010, 08:59 AM
It is a Basic MSI installation. I've gotten as far as creating a custom action with an InstallShield script that only gets executed during an uninstall. The script first attempts to delete the keys under HKLM and then the keys under HKCU. The keys under HKCU are successfully deleted, but the keys under HKLM fail to delete. It seems as if the uninstall (invoked from the control panel) is not running the script with elevated admin privileges. The installation is being run on Windows 7 x64. And this is the current script:

function DeleteRegKeys(hMSI)
// To Do: Declare local variables.
begin

// HKEY_LOCAL_MACHINE
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);

if(RegDBDeleteKey("Software\\Wow6432Node\\My Company") < 0) then
MessageBox("RegDBDeleteKey(Software\\Wow6432Node\\My Company) FAILED", SEVERE);
else
MessageBox("RegDBDeleteKey(Software\\Wow6432Node\\My Company) SUCCEEDED", INFORMATION);
endif;

if(RegDBDeleteKey("Software\\My Company") < 0) then
MessageBox("RegDBDeleteKey(Software\\My Company) FAILED", SEVERE);
else
MessageBox("RegDBDeleteKey(Software\\My Company) SUCCEEDED", INFORMATION);
endif;


// HKEY_CURRENT_USER
RegDBSetDefaultRoot(HKEY_CURRENT_USER);

if(RegDBDeleteKey("Software\\My Company") < 0) then
MessageBox("RegDBDeleteKey(Software\\My Company) FAILED", SEVERE);
else
MessageBox("RegDBDeleteKey(Software\\My Company) SUCCEEDED", INFORMATION);
endif;

end;