0

I am using winreg.DeleteKey to delete keys from the registry. I have no problems using the API; however I'm getting a weird problem where, if I delete a key from HKEY_LOCAL_MACHINE\SOFTWARE, the code successfully runs and deletes (and if i run it again it says it cannot find the key since it was just deleted), but the key is still shown in Regedit EVEN AFTER REBOOTING!

I can even edit the values of the key within Regedit! But if I try to delete the key again, WindowsError is raised that says it can't find the file specified even though it worked the first time!

Does anybody know what's happening? This is baffling, and I can't seem to find any info on this.

EDIT: Apparently a 32-bit application opens the 32-bit key, not the 64-bit key. When I try to open the key like so:

aKey = winreg.OpenKeyEx(akey, subkey_str, 0, winreg.KEY_WOW64_64KEY)

I get an "access is denied" error message. I have tried running the script with runas, opening terminal as admin. My user account has administrator privileges, and I event went so far as to check the privilege on the key itself. Administrator and all users have full access to the key.

Any ideas why I can't open it?

sugarmuff
  • 435
  • 5
  • 17
  • 2
    What keys? Could Windows be creating the keys after you try to delete them. It sets a number of keys when it reboots. – drz Jul 24 '13 at 00:30
  • Are you opening the key properly as described in the answer to the similar question [How do I Open Windows Registry with write access in Python](http://stackoverflow.com/questions/15030033/how-do-i-open-windows-registry-with-write-access-in-python)? – martineau Jul 24 '13 at 01:05
  • The keys i'm trying to delete aren't any import Windows stuff...HKEY_LOCAL_MACHINE\SOFTWARE\Native Instruments\Guitar Rig 2 – sugarmuff Jul 24 '13 at 01:18
  • in response to Martineau's comment: Yes, I am opening the keys like that. Remember, deleting keys works for everything except inside of HKEY_LOCAL_MACHINE\SOFTWARE. I have read/write access on that key, AND, as I mentioned before, the code runs fine the first time I try to delete it, but it doesn't actually delete, then the next time I run it, it says that it can't find it – sugarmuff Jul 24 '13 at 01:20
  • You may have read and write access, but make certain that you specifically have the Delete permission (you'll need to go into the Advanced permissions view to verify this.) Also, this might be a dumb question, but is there a driver still installed or other process which might be re-creating this key when you reboot? – Kudzu Jul 24 '13 at 03:21

0 Answers0