The _winreg Module

(Windows only, New in 2.0) The _winreg module provides a basic interface to the Windows registry database. Example 12-17 demonstrates the module.

Example 12-17. Using the _winreg Module

File: winreg-example-1.py

import _winreg

explorer = _winreg.OpenKey(
 _winreg.HKEY_CURRENT_USER,
 "Software\Microsoft\WindowsCurrentVersion\Explorer"
 )

#list values owned by this registry key 
try:
 i = 0
 while 1:
 name, value, type= _winreg.EnumValue(explorer, i)
 print repr(name),
 i += 1
except WindowsError:
 print

value, type = _winreg.QueryValueEx(explorer, "Logon User Name")

print
print "user is", repr(value)


'Logon User Name' 'CleanShutdown' 'ShellState' 'Shutdown Setting'
'Reason Setting' 'FaultCount' 'FaultTime' 'IconUnderline'...

user is u'Effbot'

Core Modules

More Standard Modules

Threads and Processes

Data Representation

File Formats

Mail and News Message Processing

Network Protocols

Internationalization

Multimedia Modules

Data Storage

Tools and Utilities

Platform-Specific Modules

Implementation Support Modules

Other Modules



Python Standard Library
Python Standard Library (Nutshell Handbooks) with
ISBN: 0596000960
EAN: 2147483647
Year: 2000
Pages: 252
Authors: Fredrik Lundh

Flylib.com © 2008-2020.
If you may any questions please contact us: flylib@qtcs.net