Dr.Pepper
Dr.Pepper

Reputation: 559

Python WinReg Path Wildcard

I am trying to get some values out of the registry. The problem is, one of the subkeys is "unknown". As an example, this is the key for the networked drive of "Z".
"HKEY_CURRENT_USER/Network/Z"

Here is the current basic code which looks for this specifically.

try:
    t = OpenKey(HKEY_CURRENT_USER, r"Network\\Z", 0, KEY_ALL_ACCESS)  

    i = 0
    while True:
        subkey = EnumValue(t, i)
        # print subkey[0], "  ", subkey[1]
        i += 1
except WindowsError:
    # WindowsError: [Errno 259] No more data is available
    pass

How can I add a "Wildcard" to the "Network\Z" part in case their is more than one network path other than Z?

Upvotes: 0

Views: 253

Answers (1)

kirbyfan64sos
kirbyfan64sos

Reputation: 10727

UNTESTED:

key = OpenKey(HKEY_CURRENT_USER, 'Network', 0, KEY_ALL_ACCESS) # Open the root Network key.
ndrives = QueryInfoKey(key)[0] # Get the number of subkeys inside.
for i in range(ndrives): # For each subkey index...
    drive = EnumKey(key, i) # Get the subkey name.
    t = OpenKey(HKEY_CURRENR_USER, 'Network\\' + drive, 0, KEY_ALL_ACCESS) # Open the drive key.
    # Do stuff with t.

Upvotes: 1

Related Questions