From 06e230f7209606d667730a6fe9b3a26096152dae Mon Sep 17 00:00:00 2001 From: dan oak Date: Sat, 20 Apr 2024 18:33:06 +0300 Subject: [PATCH] native-messaging: fix not to fail on missing HKCU when HKLM is set there was a bug when missing key in HKEY_CURRENT_USER would throw from `winreg.OpenKey` call --- native-messaging/check_config_win.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/native-messaging/check_config_win.py b/native-messaging/check_config_win.py index 3bbfcaf..d1d0ae3 100755 --- a/native-messaging/check_config_win.py +++ b/native-messaging/check_config_win.py @@ -16,21 +16,15 @@ key_path = 'Software\\Mozilla\\NativeMessagingHosts\\ping_pong' # Assuming current user overrides local machine. key_roots = ['HKEY_CURRENT_USER', 'HKEY_LOCAL_MACHINE'] -found_key = False - -for root in key_roots: - key = winreg.OpenKey(getattr(winreg, root), key_path) +for key_root in key_roots: try: - print('Checking:', root, key_path) + print('Checking:', key_root, key_path) + key = winreg.OpenKey(getattr(winreg, key_root), key_path) res = winreg.QueryValueEx(key, '') + break except FileNotFoundError: - print('...error finding key') - continue - - found_key = True - break - -if not found_key: + print('... error finding key') +else: raise ValueError('Could not find a registry entry, aborting.') json_path = res[0]