Help with reading WinXP registry

ChrisH secun at yahoo.com
Mon Aug 16 14:27:05 EDT 2004


Here is an example.

from _winreg import *

print r"*** Reading from SOFTWARE\Microsoft\Windows\CurrentVersion\Run 
***"
aReg = ConnectRegistry(None,HKEY_LOCAL_MACHINE)

aKey = OpenKey(aReg, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Run") 
for i in range(1024):                                           
    try:
        n,v,t = EnumValue(aKey,i)
        print i, n, v, t
    except EnvironmentError:                                               
        print "You have",i," tasks starting at logon..."
        break          
CloseKey(aKey)                                                  

print r"*** Writing to SOFTWARE\Microsoft\Windows\CurrentVersion\Run 
***"
aKey = OpenKey(aReg, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", 
0, KEY_WRITE)
try:   
   SetValueEx(aKey,"MyNewKey",0, REG_SZ, r"c:\winnt\explorer.exe") 
except EnvironmentError:                                          
    print "Encountered problems writing into the Registry..."
CloseKey(aKey)

CloseKey(aReg)            





In article <mailman.1744.1092674965.5135.python-list at python.org>, 
miki.tebeka at zoran.com says...
> Hello David,
> 
> > Is there a better way to access the registry in a Win32 system?
> Try the _winreg module with the ...Ex functions.
> 
> HTH.
> --
> ------------------------------------------------------------------------
> Miki Tebeka <miki.tebeka at zoran.com>
> http://tebeka.spymac.net
> The only difference between children and adults is the price of the toys
> 



More information about the Python-list mailing list