2016-06-06 132 views
0

我想從註冊表中獲取一些值。問題是,其中一個子項是「未知」。例如,這是「Z」網絡驅動器的關鍵。
「HKEY_CURRENT_USER/Network/Z」Python WinReg路徑通配符

這裏是目前的基本代碼,它具體尋找這個。

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 

如何將「通配符」添加到「網絡\ Z」部分,以防萬一他們的網絡路徑不是Z?

回答

1

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. 
+0

三江源。我剛剛發現了「EnumKey」功能。現在用它進行測試。 –