1

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

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

1 Comment

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

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 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.