[Tutor] help with _winreg
Danny Yoo
dyoo@hkn.eecs.berkeley.edu
Fri, 27 Jul 2001 13:50:51 -0700 (PDT)
On Fri, 27 Jul 2001, James wrote:
> 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")
According to the documentation here:
http://python.org/doc/lib/module--winreg.html
you'll probably need to tell OpenKey() that you want to have write access
to the registry keys:
###
OpenKey(key, sub_key[, res = 0][, sam = KEY_READ])
[... some text cut]
sam is an integer that specifies an access mask that describes the
desired security access for the key. Default is KEY_READ
###
That's probably why the changes aren't being saved. I don't know what the
exact flag is, since I'm not running Windows, but I'm guessing it's
something like KEY_WRITE. Back up your registry; it's tricky work!
You might also want to ask questions on _winreg on the main
comp.lang.python newsgroup; I'm not sure how many of us here are familiar
enough with _winreg to help you effectively.
Good luck to you!