_winreg - Windows registry access

Mark Hammond MarkH at ActiveState.com
Sat Feb 24 09:45:42 EST 2001


Larry Bates wrote:

> I'm a newbie, so please forgive me.  Does anyone have any example code on
> how to use the new _winreg class?  I've tried everything that makes sense,
> but
> nothing seems to work.  Examples sure go a long way when you are learning.

Here is a really simple one:

>>> import _winreg, sys
>>> key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "Software\\Python\\PythonCore\\" + sys.winver + "\\PythonPath")
>>> _winreg.QueryValue(key, "")
'f:\\src\\python-cvs\\lib;f:\\src\\python-cvs\\pcbuild'
>>> _winreg.EnumKey(key, 0)
'Pythonwin'
>>> _winreg.EnumKey(key, 1)
'win32'
>>>

This shows the default PythonPath for my current version, and shows that I have at least 2 keys under this, called "Pythonwin" and "win32".  It doesnt show the values for these 2 subkeys.

Mark.

-- 
Nominate Your Favorite Programmers
for the Perl and Python Active Awards!
http://www.ActiveState.com/Awards/




More information about the Python-list mailing list