Created
August 3, 2020 19:02
-
-
Save heetbeet/b9209e47bb954556db0e91b7fa91ecd9 to your computer and use it in GitHub Desktop.
Walk through windows registry
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import winreg | |
from contextlib import suppress | |
import itertools | |
from path import Path | |
def subkeys(path, hkey=winreg.HKEY_CURRENT_USER): | |
flags=0 | |
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