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.HKEY
something; 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
2010-03-01 04:20:08
python 2.6 here =/
Shady
2010-03-01 04:22:43
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
2010-03-01 04:25:51
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
2010-03-01 04:35:03