解开这个老问题,以下是chrishebert递归函数的更新版本:处理python3(用python3.7.1测试)
处理多个注册表体系结构(例如Wow64 for Python 32 on Windows 64)
PEP-8是否符合要求
下面的示例显示了使用体系结构键掩码删除所有注册表体系结构(标准和重定向的WOW6432Node)中的两个键的函数用法。
希望这能帮助某些人:import winreg
def delete_sub_key(key0, current_key, arch_key=0):
open_key = winreg.OpenKey(key0, current_key, 0, winreg.KEY_ALL_ACCESS | arch_key)
info_key = winreg.QueryInfoKey(open_key)
for x in range(0, info_key[0]):
# NOTE:: This code is to delete the key and all sub_keys.
# If you just want to walk through them, then
# you should pass x to EnumKey. sub_key = winreg.EnumKey(open_key, x)
# Deleting the sub_key will change the sub_key count used by EnumKey.
# We must always pass 0 to EnumKey so we
# always get back the new first sub_key.
sub_key = winreg.EnumKey(open_key, 0)
try: