From ba3943da9792dffdfe39f3e4014b506cfd7b91e9 Mon Sep 17 00:00:00 2001 From: g1879 Date: Sat, 26 Dec 2020 17:46:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BB=8E=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=E8=A1=A8=E8=8E=B7=E5=8F=96chrome.exe=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/easy_set.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/DrissionPage/easy_set.py b/DrissionPage/easy_set.py index a64fadb..cb93160 100644 --- a/DrissionPage/easy_set.py +++ b/DrissionPage/easy_set.py @@ -277,10 +277,30 @@ def _get_chrome_path(ini_path: str = None, show_msg: bool = True) -> Union[str, for path in paths: path = Path(path) / 'chrome.exe' - if path.exists(): - if show_msg: - print('系统中', end='') - return str(path) + try: + if path.exists(): + if show_msg: + print('系统变量中', end='') + return str(path) + except OSError: + pass + + # -----------从注册表中获取-------------- + import winreg + try: + key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, + r'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe', + reserved=0, access=winreg.KEY_READ) + k = winreg.EnumValue(key, 0) + winreg.CloseKey(key) + + if show_msg: + print('注册表中', end='') + + return k[1] + + except FileNotFoundError: + return def _get_chrome_version(path: str) -> Union[str, None]: