如何在Windows系统中用Python检查是否已安装Chrome
在Windows中检查Chrome浏览器是否已安装的方法
一、手动检测方式
- 直接在开始菜单搜索框输入
Chrome,能搜到结果则说明已安装 - 检查默认安装路径:
- 64位Chrome通常在:
C:\Program Files\Google\Chrome\Application\chrome.exe - 32位Chrome或32位系统下的Chrome在:
C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
- 64位Chrome通常在:
- 通过注册表验证:
- 按下
Win+R输入regedit打开注册表编辑器 - 导航到
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe,若该键值存在且指向有效可执行文件,说明Chrome已安装
- 按下
二、Python代码实现检测
下面提供两种可靠的检测方案,覆盖不同场景:
方案1:检查默认安装路径
这种方式简单直接,适合大多数默认安装的情况:
import os def check_chrome_installation(): # 列出Chrome的常见默认安装路径 common_paths = [ r"C:\Program Files\Google\Chrome\Application\chrome.exe", r"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" ] for path in common_paths: if os.path.isfile(path): return (True, path) return (False, None) # 调用示例 is_installed, chrome_location = check_chrome_installation() if is_installed: print(f"Chrome已找到,安装路径:{chrome_location}") else: print("未检测到Chrome浏览器")
方案2:读取Windows注册表
这种方式能检测到自定义安装路径的Chrome,但需要管理员权限运行:
import os import winreg def check_chrome_via_registry(): try: # 打开Chrome对应的注册表项 reg_key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe") # 获取注册表中存储的Chrome路径 chrome_path, _ = winreg.QueryValueEx(reg_key, "") winreg.CloseKey(reg_key) # 验证路径是否有效 if os.path.isfile(chrome_path): return (True, chrome_path) return (False, None) except FileNotFoundError: # 注册表项不存在,说明未安装 return (False, None) except Exception as e: print(f"读取注册表时出现错误:{str(e)}") return (False, None) # 调用示例 is_installed, chrome_location = check_chrome_via_registry() if is_installed: print(f"Chrome已找到,安装路径:{chrome_location}") else: print("未检测到Chrome浏览器")
注意事项
- 注册表检测方式需要以管理员身份运行Python脚本,否则可能因权限不足无法读取注册表项
- 若用户将Chrome安装在自定义路径,仅检查默认路径会出现漏判,结合注册表检测能提升准确率
内容的提问来源于stack exchange,提问作者Julian
相关产品推荐
相关产品推荐

