The code is under here. Just run and see what will happen.
import winreg
key_dict = {}
regedit = {}
def get_key(hand, path):
index = 0
flag = True
while flag:
try:
key = winreg.EnumKey(hand, index)
complete = path + "\\" + key
next_hand = winreg.OpenKey(hand, key, reserved=0, access=winreg.KEY_READ)
key_dict[complete] = next_hand
get_key(next_hand, complete)
index += 1
except Exception as e:
if e.__str__() != "[WinError 259] 没有可用的数据了。":
print("\033[1;31m Fatal: {} \033[0m".format(e))
flag = False
return
def get_reg(reg_root, path_root):
print("Starting reading {} key......".format(path_root))
get_key(reg_root, "\\{}".format(path_root))
print("Reading {} key successfully!".format(path_root))
print("Starting reading {} regedit......".format(path_root))
for path, father_key in key_dict.items():
# print(path)
i = 0
flag = True
while flag:
try:
r = winreg.EnumValue(father_key, i)
key = r[0]
value = r[1]
if isinstance(value, list):
value = tuple(value)
if isinstance(value, bytes):
value = int.from_bytes(value, "big")
key = "{}\\{}".format(path, key)
# print(key)
regedit[key] = value
# try:
# if isinstance(regedit[key], list):
# regedit[key].append(value)
# else:
# regedit[key] = [regedit[key], value]
# except KeyError:
# regedit[key] = value
i += 1
except OSError as e:
if e.__str__() != "[WinError 259] 没有可用的数据了。":
print("\033[1;31m Fatal: {} \033[0m".format(e))
print("\033[1;41m Problem: {} \033[0m".format("{}\\{}".format(path, key)))
flag = False
print("Reading {} regedit successfully!".format(path_root))
def clear():
key_dict = {}
regedit = {}
root_key = [
winreg.HKEY_CURRENT_USER,
winreg.HKEY_LOCAL_MACHINE,
winreg.HKEY_USERS,
winreg.HKEY_CLASSES_ROOT,
winreg.HKEY_CURRENT_CONFIG,
]
root_path = [
"HKEY_CURRENT_USER",
"HKEY_LOCAL_MACHINE",
"HKEY_USERS",
"HKEY_CLASSES_ROOT",
"HKEY_HKEY_CURRENT_CONFIG"
]
def record():
result = []
for i in range(len(root_key)):
print("Reading {}".format(root_path[i]))
get_reg(root_key[i], root_path[i])
result.append(regedit)
return result
print(record())