Skip to content

Instantly share code, notes, and snippets.

Created August 3, 2020 19:02
What would you like to do?
Walk through windows registry
import winreg
from contextlib import suppress
import itertools
from path import Path
def subkeys(path, hkey=winreg.HKEY_CURRENT_USER):
with suppress(WindowsError), winreg.OpenKey(hkey, path, 0, winreg.KEY_READ|flags) as k:
for i in itertools.count():
yield winreg.EnumKey(k, i)
def keywalk(path=""):
for key in subkeys(path):
nextpath = key if path=="" else path+"\\"+key
yield nextpath
yield from keywalk(nextpath)
def regwalk(path=""):
for key in keywalk(path):
keyread = winreg.OpenKey(winreg.HKEY_CURRENT_USER, key, 0, winreg.KEY_READ)
for i in range(0, winreg.QueryInfoKey(keyread)[1]):
param, value, regtype = winreg.EnumValue(keyread, i)
yield key+"\\"+param, (value, regtype)
regcapture = {}
for key, value in regwalk():
regcapture[key] = value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment