winreg

About WinReg

Winreg is an object-oriented wrapper of the _winreg module. It allows for easy access to and manipulation of the Windows Registry, in a consistent manner.

Notes

As of version 0.2, WinReg requires Python 2.2. If people would like to be able to use WinReg with earlier versions, please let me know.

Examples

Turn on tab completion in cmd.exe in NT/2000

>>> from winreg import *
>>> key = Key(HKCU, 'SOFTWARE\\Microsoft\\Command Processor')
>>> if key.values['CompletionChar'] != 9:
...     key.values['CompletionChar'] = 9
>>>

Fiddling about

>>> from winreg import Key
>>> key = Key('HKEY_CLASSES_ROOT', '.py')
>>> print len(key.keys)
0
>>> print len(key.values)
2
>>> for v in key.values:
...     print "%s=%s" % (`v.name`, v.value,)
''=Python.File
'Content Type'=text/plain
>>> v = key.values.set('{test}', 'delete me')
>>> print len(key.value)
3
>>> print v.value
delete me
>>> v.delete()
>>> print len(key.values)
2

To Do

  • tutorial
  • keys should always know their names and paths
  • api docs
  • example app for setting env vars
  • HKLM missing from __all__ ?
  • intercept 'get' for Values and return a list?
  • example to print the key registry keys and values

License

Python License.

Version History

Version 0.3 (2002-04-21)

  • KeyIterator bugfixes
  • Added doctests for KeyIterator and ValueIterator

Version 0.2 (2001-12-28)

  • re-write of v0.1, which I lost, with Python 2.2

Version 0.1 (2001-07-24)

  • initial release

Contact

Please feel free to contact me with questions, comments, suggestions, or bug reports at oliver@rutherfurd.net.