The winreg Module Manipulate the Windows Registry

PC Repair Tools

Advanced Registry Cleaner PC Diagnosis and Repair

Get Instant Access

The Windows Registry is a database that contains program and system information and settings. Often it can be useful to access the Registry (to read from it or write to it) via a script. The winreg module makes this easy to do in Python.

Example

The following example queries a particular key in the Registry and outputs all the subkeys for that key:

import _winreg explorer = _winreg.OpenKey(

_winreg.HKEY_CURRENT_USER,

"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer")

# list values owned by this registry key i = 0

try:

while 1:

name, value, type = _winreg.EnumValue(explorer, i) print repr(name), i += 1

except: print

The following is the output for this program:

I:\Applied_Python\Chapter_9-mython winreg-example1.py

'ShellState' 'CleanShutdown' 'Browse For Folder Width' 'Browse For Folder Height ' 'link' 'Logon User Name'

Was this article helpful?

0 0

Post a comment