import winreg
def get_wechat_install_path():
try:
# 尝试在 HKEY_LOCAL_MACHINE 中查找微信安装路径
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\WOW6432Node\Tencent\WeChat")
install_path, _ = winreg.QueryValueEx(key, "InstallPath")
return install_path
except FileNotFoundError:
try:
# 如果在 HKEY_LOCAL_MACHINE 中未找到,尝试在 HKEY_CURRENT_USER 中查找
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r"Software\Tencent\WeChat")
install_path, _ = winreg.QueryValueEx(key, "InstallPath")
return install_path
except FileNotFoundError:
return "微信安装路径未找到"
except Exception as e:
return f"发生错误: {e}"
# 获取并打印微信安装路径
wechat_install_path = get_wechat_install_path()
print("微信安装路径:", wechat_install_path)
python通过注册表获取应用根路径
最新推荐文章于 2024-11-03 12:02:27 发布