views:

38

answers:

2

How is the simpler way to verify if the value is already created or create Windows registry values ?

+3  A: 

Use the standard Python library module _winreg (it's renamed to winreg, no leading _, if you're using Python 3).

You always start with one of the constant keys named _winreg.HKEYsomething; to see them all, do:

 >>> import _winreg
 >>> [k for k in dir(_winreg) if k.startswith('HKEY')]

and repeatedly use (to navigate down the keys' tree) functions such as _winreg.Openkey (in a try/except to catch the WindowsError it raises when a key is not present).

Alex Martelli
python 2.6 here =/
Shady
So it's `_winreg`, as I said first (most people are on Python 2.something, and `_winreg` is how the module is named from Python 2.0 to 2.7).
Alex Martelli
A: 

you can use _winreg. here's an example enumerating the startup(Run)

import _winreg
j=0
startup = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Run")
while 1:
    try:
        print  _winreg.EnumValue(startup,j)
        j+=1
    except : break 
ghostdog74