Python code to read registry

后端 未结 5 1942
from _winreg import *

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


        
5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-01 12:44

    Documentation says that EnumKey returns string with key's name. You have to explicitly open it with _winreg.OpenKey function. I've fixed your code snippet:

    
    from _winreg import *
    
    aKey = r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
    aReg = ConnectRegistry(None,HKEY_LOCAL_MACHINE)
    
    print r"*** Reading from %s ***" % aKey
    
    aKey = OpenKey(aReg, aKey)
    for i in range(1024):
        try:
            asubkey_name=EnumKey(aKey,i)
            asubkey=OpenKey(aKey,asubkey_name)
            val=QueryValueEx(asubkey, "DisplayName")
            print val
        except EnvironmentError:
            break
    

    Please note, that not every key has "DisplayName" value available.

提交回复
热议问题