Archive: DeleteRegKey Fails Because Not Iterating All Subkeys


DeleteRegKey Fails Because Not Iterating All Subkeys
  I call DeleteRegKey in an Uninstall section and it fails to remove the registry key. Looking at the registry after the uninstall, only one of four subkeys has been deleted, which explains the failure. Using sysinternals Process Monitor, I see that it iterates the subkeys, but stops on the first one. Oddly, after it has deleted and closed the first subkey, it then tries to reopen that same subkey, which of course fails because it does not exist any longer. It's almost as if it tries to process the same subkey a second time instead of moving on to the next subkey.

A few more twists. This exact same script code worked fine when compiled with a version of NSIS prior to 2.39 (not sure exactly which version), but now fails with the latest version 2.45. Also, this is failing on Vista, but working on XP (again, used to work on both Vista and XP with a prior NSIS version). Note that I do use "RequestExecutionLevel admin" in my script, so I don't believe it's a elevation level issue. Lastly, I copied/pasted out the problem area of my script and created a test script. That test script works fine.

Here is a snippet of the code:


; Must first remove the deny permission on Globals.
AccessControl::GrantOnRegKey HKLM "Software\SoftwareTime\ComputerTime\Globals" "(S-1-5-32-545)" "EnumerateSubKeys"
ClearErrors
DeleteRegKey HKLM "Software\SoftwareTime\ComputerTime"
${If} ${Errors}
MessageBox MB_OK "Error removing registry key."
${EndIf}

Vista adds extra fun with virtual registries. Did you add a manifest using RequestExecutionLevel? If you did, make sure you have permission to delete those keys and make sure there isn't another copy of it somewhere else in the registry.


Yes, I did use RequestExecutionLevel, and keep in mind this same exact script worked with an earlier version of NSIS, but fails with version 2.45.

Here's the important part -- I looked at the NSIS C source code and compared it to the Process Monitor output that shows events on the registry. In exechead\exec.c\myDeleteRegKeyEx(), it does not recurse into itself for each subkey according to the output log of Process Monitor, very odd. So it appears to be an issue at the level below my script in the runtime engine of NSIS itself.

However, in a smaller test script, it *does* recurse properly into itself on each subkey. I am totally baffled and looking for suggestions as what to try next. Thanks!


i know this is an old post.. but is the closest post that is relevant to my question.

is there a recursive switch for AccessControl?
SetACL has


rec 

>
i looked through AccessControl's documents but didn't see anything.

If it's not in the documentation, it's probably not in the plugin either. Of course you're more than welcome to modify the accesscontrol plugin, and submit a patch for the code to the bug tracker.


thank you for answering.

i wasn't sure if there was a trick or something to make it work recursively that wasn't documented.

thanks again.