import winreg
# TODO 定义Registration
# TODO 查看注册表 计算机\HKEY_CURRENT_USER\Software\PremiumSoft\NavicatPremium ,我是Registration15XCS
Registration = "Registration15XCS"
def contains_info_subkey(key):
try:
index = 0
while True:
sub_key_name = winreg.EnumKey(key, index)
if sub_key_name == "Info":
return True
index += 1
except OSError:
return False
def delete_subkey(key, sub_key_name):
try:
winreg.DeleteKey(key, sub_key_name)
print(f"删除子键: {sub_key_name}")
except OSError as e:
pass
def print_registry_subkeys(root_key, path, indent=0, should_print=True):
try:
key = winreg.OpenKey(root_key, path, 0, winreg.KEY_READ | winreg.KEY_WRITE)
index = 0
while True:
try:
sub_key_name = winreg.EnumKey(key, index)
full_path = f"{path}\\{sub_key_name}"
# TODO 检查子键名称是否以 "Registration"、"Update" 结尾
# TODO 或者检查子键中是否包含 "Info" 子键
if sub_key_name.endswith(Registration) or sub_key_name.endswith("Update"):
should_print = True
delete_subkey(root_key, full_path)
else:
# TODO 尝试打开子键,检查是否包含 "Info" 子键
try:
sub_key = winreg.OpenKey(key, sub_key_name, 0, winreg.KEY_READ | winreg.KEY_WRITE)
if contains_info_subkey(sub_key):
should_print = True
delete_subkey(sub_key, "Info")
else:
should_print = False
winreg.CloseKey(sub_key)
except OSError:
should_print = False
if should_print:
print(" " * indent + full_path)
# TODO 递归调用,增加缩进
print_registry_subkeys(root_key, full_path, indent + 1, should_print)
index += 1
except OSError:
break
winreg.CloseKey(key)
except OSError as e:
pass
if __name__ == "__main__":
root_key = winreg.HKEY_CURRENT_USER
navicat_path = r"Software\PremiumSoft\NavicatPremium"
print("以下是 NavicatPremium 路径下的子键信息:")
print_registry_subkeys(root_key, navicat_path)
print()
clsid_path = r"Software\Classes\CLSID"
print("以下是 CLSID 路径下的所有子键及其Info子键信息:")
print_registry_subkeys(root_key, clsid_path)
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。