Archive: DeleteRegKey shenanigans


DeleteRegKey shenanigans
Ok, so I just hosed the registry entries for my program due to a bug/feature of DeleteRegKey.

I am creating a registry key, with a few values. During the uninstallation, I delete ONE of these registry values, then try to delete the registry key using /ifempty like this:

DeleteRegKey /ifempty HKLM "${REG_KEY}\CurrentVersion"

There are no sub-keys of the CurrentVersion key, but there are still values in the key. So why does DeleteRegKey with delete that key when I'm using the ifempty?

See attached script for a simple example

From the NSIS User Manual (http://nsis.sourceforge.net/Docs/Chapter4.html#4.9.2.3):

If /ifempty is specified, the registry key will only be deleted if it has no subkeys (otherwise, the whole registry tree will be removed).
The command is behaving as described in the manual.

Root cause found
Ok, so I've found the root cause for this problem. It turns out that the NSIS command DeleteRegKey is working just fine. The C++ code behind it in 'NSIS\Source\exehead\exec.c' is actually calling RegDeleteKey. According to the MSDN Platform SDK documentation, The RegDeleteKey function deletes a subkey, including all of its values.

So thats how I hosed the registry values :(

But I've found a solution. SHDeleteEmptyKey will delete an empty key (one with no subkeys and no values) according to the MSDN docs. That is a function of 'shlwapi.dll' which is a part of IE 4.0 and later.

Now if anyone can tell me in a hurry how to call that function, please do. Otherwise I'll figure it out eventually.


u can call SHDeleteEmptyKey with the system plugin...