[Tutor] help with _winreg

James sendme105@hotmail.com
Fri, 27 Jul 2001 00:09:53 -0700


I'm experimenting with _winreg on python 2.1, and I'm having problems with
the
RegLoadKey(key, sub_key, file_name) function.  I get "NameError: name
'RegLoadKey' is not defined."

On a hunch I tried LoadKey(key, sub_key, file_name) and it appeared to work.
But when I checked the registry, I got an unexpected result.

My code:

rKey= ConnectRegistry(None,HKEY_LOCAL_MACHINE)
aKey=OpenKey(rKey, r"Software\testkey1")
dirKey=OpenKey(rKey, r"Software")

SaveKey(aKey, r"c:\python\Scripts\tmpkey")
LoadKey(rKey, r"SOFTWARE\testkey2", r"c:\python\Scripts\tmpkey")

Result:

I open regedit, and in the HKEY_LOCAL_MACHINE key/folder I get the expected
'Software' key/folder, then just below it I get a folder named
"SOFTWARE\testkey2" that won't open and won't delete.  If I reset the
computer and check again, it is gone.

(I also tried to use LoadKey(dirKey, r"testkey2",
r"c:\python\Scripts\tmpkey") to no avail, the function objecting to dirKey
as input.)


Also, regarding 'DeleteKey(key, sub_key)' the documentation says :

"sub_key is a string that must be a subkey of the key identified by the key
parameter. This value must not be None, and the *key may not have subkeys.*"

However, if I use this function to delete 'testkey1' above, it appears to
work even if 'testkey1' has subkeys.  As in: DeleteKey(dirKey, "testkey1")
So I think I'm missing something...


What I'm trying to accomplish:  I want to rename
HKEY_LOCAL_MACHINE\SOFTWARE\testkey1 to
HKEY_LOCAL_MACHINE\SOFTWARE\testkey2.

Maybe there are easier ways to do this?

Thanks.