From 4bfe9b1e4c11f6944fa253e06a2edfeb574af269 Mon Sep 17 00:00:00 2001 From: Abdul Haseeb Date: Thu, 24 Dec 2020 20:56:22 +0530 Subject: [PATCH 1/4] WinSCP: Fix case mismatch while comparing links --- WinSCP/winscp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WinSCP/winscp.py b/WinSCP/winscp.py index 0b5d63b..f65f7a6 100644 --- a/WinSCP/winscp.py +++ b/WinSCP/winscp.py @@ -309,7 +309,7 @@ def _autodetect_startmenu(self, exe_name, name_pattern): for link_file in found_link_files: try: link_props = kpu.read_link(link_file) - if (link_props['target'].lower().endswith(exe_name) and + if (link_props['target'].endswith(exe_name) and os.path.exists(link_props['target'])): return link_props['target'] except Exception as exc: From 22dbeca4e482e1710dfd47c1126069aeeec42765 Mon Sep 17 00:00:00 2001 From: Abdul Haseeb Date: Thu, 24 Dec 2020 20:26:19 +0530 Subject: [PATCH 2/4] WinSCP: Look in StartMenu/Programs for autodetection --- WinSCP/winscp.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/WinSCP/winscp.py b/WinSCP/winscp.py index f65f7a6..ebceef2 100644 --- a/WinSCP/winscp.py +++ b/WinSCP/winscp.py @@ -291,8 +291,9 @@ def _autodetect_official_progfiles(self): def _autodetect_startmenu(self, exe_name, name_pattern): known_folders = ( - "{625b53c3-ab48-4ec1-ba1f-a1ef4146fc19}", # FOLDERID_StartMenu - "{a4115719-d62e-491d-aa7c-e74b8be3b067}") # FOLDERID_CommonStartMenu + "{625b53c3-ab48-4ec1-ba1f-a1ef4146fc19}", # FOLDERID_StartMenu + "{a4115719-d62e-491d-aa7c-e74b8be3b067}", # FOLDERID_CommonStartMenu + "{a77f5d77-2e2b-44c3-a6a2-aba601054a51}",) # FOLDERID_Programs found_link_files = [] for kf_guid in known_folders: From a5785a689e26e104eb651ecbc490acef6658004a Mon Sep 17 00:00:00 2001 From: Abdul Haseeb Date: Thu, 24 Dec 2020 20:38:42 +0530 Subject: [PATCH 3/4] WinSCP: Search for path in HKCU as well --- WinSCP/winscp.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/WinSCP/winscp.py b/WinSCP/winscp.py index ebceef2..18a77c9 100644 --- a/WinSCP/winscp.py +++ b/WinSCP/winscp.py @@ -267,10 +267,10 @@ def _detect_distro_official(self, given_enabled, given_label, given_path, given_ - def _autodetect_official_installreg(self): + def _exe_from_reg(self, reg_root): try: key = winreg.OpenKey( - winreg.HKEY_LOCAL_MACHINE, + reg_root, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\winscp3_is1", access=winreg.KEY_READ | winreg.KEY_WOW64_32KEY) value = winreg.QueryValueEx(key, "InstallLocation")[0] @@ -282,6 +282,11 @@ def _autodetect_official_installreg(self): pass return None + def _autodetect_official_installreg(self): + hklm = self._exe_from_reg(winreg.HKEY_LOCAL_MACHINE) + return (hklm if hklm is not None + else self._exe_from_reg(winreg.HKEY_CURRENT_USER)) + def _autodetect_official_progfiles(self): for hive in ('%PROGRAMFILES%', '%PROGRAMFILES(X86)%'): exe_file = os.path.join( From 5ca79d9ec9df95b0c8b822a299a4b56bf4a7814c Mon Sep 17 00:00:00 2001 From: Sam Glider Date: Fri, 28 May 2021 11:42:22 +0530 Subject: [PATCH 4/4] WinSCP: Prioritise HKCU over HKLM (#3) --- WinSCP/winscp.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/WinSCP/winscp.py b/WinSCP/winscp.py index 18a77c9..842637f 100644 --- a/WinSCP/winscp.py +++ b/WinSCP/winscp.py @@ -283,9 +283,9 @@ def _exe_from_reg(self, reg_root): return None def _autodetect_official_installreg(self): - hklm = self._exe_from_reg(winreg.HKEY_LOCAL_MACHINE) - return (hklm if hklm is not None - else self._exe_from_reg(winreg.HKEY_CURRENT_USER)) + hkcu = self._exe_from_reg(winreg.HKEY_CURRENT_USER) + return (hkcu if hkcu is not None + else self._exe_from_reg(winreg.HKEY_LOCAL_MACHINE)) def _autodetect_official_progfiles(self): for hive in ('%PROGRAMFILES%', '%PROGRAMFILES(X86)%'):