from winreg import *
import re
def subRegKey(key, pattern, patchlist):
# 个数
count = QueryInfoKey(key)[0]
for index in range(count):
# 获取标题
name = EnumKey(key, index)
if name and name[0:1]=='v':
print(name)
result = patch.match(name)
if result:
patchlist.append(result.group(1))
sub = OpenKey(key, name)
subRegKey(sub, pattern, patchlist)
CloseKey(sub)
if __name__ == '__main__':
patchlist = []
updates = 'SOFTWARE\Microsoft\\NET Framework Setup\\NDP'
patch = re.compile('(v\d{1}\.\d{1})*')
#patch = re.compile('(v\d{1})')
#patch = re.compile('v*')
key = OpenKey(HKEY_LOCAL_MACHINE, updates)
subRegKey(key, patch, patchlist)
#subRegKey(key,patchlist)
print('Count: ' + str(len(patchlist)))
for p in patchlist:
if p:
print(p)
CloseKey(key)