0

what id did is........this code loops itself among keys and subkeys and checks if the key has any values if present prints values. For this code the pointer or whatever moves from HKEY_CURRENT_CONFIG to System and to CurrentControlSet and CurrentControlSet has one value(i manually created it) but the error iam getting as

Traceback (most recent call last): System File "C:/Users/siva kumar/PycharmProjects/delete this/3.py", line 34, in System\CurrentControlSet traverse_registry_tree(winreg.HKEY_CURRENT_CONFIG, keypath) r"System\CurrentControlSet" File "C:/Users/siva kumar/PycharmProjects/delete this/3.py", line 21, in traverse_registry_tree x = winreg.OpenKey(winreg.HKEY_CURRENT_CONFIG, y, 0, winreg.KEY_READ | winreg.KEY_WOW64_32KEY) #%('r',subkeypath) FileNotFoundError: [WinError 2] The system cannot find the file specified

import winreg

def subkeys(key):
    i = 0
    while True:
        try:
            subkey = winreg.EnumKey(key, i)
            yield subkey
            i+=1
        except WindowsError as e:
            break

def traverse_registry_tree(hkey, keypath, tabs=1):
    key = winreg.OpenKey(hkey, keypath, 0, winreg.KEY_READ)
    for subkeyname in subkeys(key):

        subkeypath = "%s\\%s" % (keypath, subkeyname)
        print(subkeypath)
        y='%s''"%s"' %('r',subkeypath)
        print(y)
        x = winreg.OpenKey(winreg.HKEY_CURRENT_CONFIG, y, 0, winreg.KEY_READ)

        z=winreg.QueryInfoKey(x)[1]
        print(z)

        if z!=0:
            for i in range(0, z):
                print(winreg.EnumValue(key, i))

    traverse_registry_tree(hkey, subkeypath, tabs+1)

keypath = r"System"
print("System")
traverse_registry_tree(winreg.HKEY_CURRENT_CONFIG, keypath)
  • Possible duplicate of [Loop through values or registry key.. \_winreg Python](http://stackoverflow.com/questions/3974038/loop-through-values-or-registry-key-winreg-python) – Jeff B Feb 27 '17 at 16:02
  • Have you taken a look at these related questions? http://stackoverflow.com/q/3974038/ and http://stackoverflow.com/q/6053867/ – Jeff B Feb 27 '17 at 16:03
  • Choose a hive and enumerate the keys values and recursively enumerate the subkeys. For the starting hive, there's a pseudo-handle for the `HKEY_LOCAL_MACHINE` hive and a pseudo-handle for the `HKEY_USERS` key that has the loaded user hives as subkeys named for the user SID. A user's "Classes" subkey is actually a separate hive that's linked into the "Software" key of the user's primary hive. – Eryk Sun Feb 27 '17 at 16:25
  • Skip symbolic links. To test for this, open a key with the keyword argument `reserved=winreg.REG_OPTION_OPEN_LINK` and query the value `"SymbolicLinkValue"`. If that succeeds, you know it's a link that should be skipped. – Eryk Sun Feb 27 '17 at 16:26

0 Answers0