Bruno 'Shady'
Bruno 'Shady'

Reputation: 4516

How can I verify and create values on the Windows registry with Python?

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

Upvotes: 1

Views: 951

Answers (2)

ghostdog74
ghostdog74

Reputation: 342303

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 

Upvotes: 1

Alex Martelli
Alex Martelli

Reputation: 881537

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).

Upvotes: 3

Related Questions