[Python] Python winreg looping through sub-keys

Discussão em 'Python' iniciado por Stack, Agosto 3, 2025.

  1. Stack

    Stack Membro Participativo

    I'm able to successfully retrieve the 5 sub-keys from my windows 7 machine registry hive "HKEY_LOCAL_MACHINE" with the code below.

    from _winreg import *

    try:
    i = 0
    while True:
    subkey = EnumKey(HKEY_LOCAL_MACHINE, i)
    print subkey
    i += 1
    except WindowsError:
    pass


    My question is, how do I then enumerate the keys under those? I want to end up listing all the keys in the SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Signatures\Unmanaged folder but I can't figure out how to step my way down there.

    In response to the first comment, I ran this code on my machine and while it didn't error out, it didn't produce results.

    from _winreg import *

    aReg = ConnectRegistry(None,HKEY_LOCAL_MACHINE)
    aKey = OpenKey(aReg, r"SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Signatures\Unmanaged")
    for i in range(1024):
    try:
    keyname = EnumKey(aKey, i)
    asubkey = OpenKey(aKey, keyname)
    val = QueryValueEx(asubkey, "Description")
    print val
    except WindowsError:
    break


    A regedit or reg query shows 6 values in that folder but I can't get a python script to show me those six.

    Continue reading...

Compartilhe esta Página