Skip to content

Commit

Permalink
native-messaging: fix not to fail on missing HKCU when HKLM is set
Browse files Browse the repository at this point in the history
there was a bug when missing key in HKEY_CURRENT_USER would throw from `winreg.OpenKey` call
  • Loading branch information
dahn-zk committed Apr 20, 2024
1 parent faadfca commit 06e230f
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions native-messaging/check_config_win.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,15 @@
# 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]
Expand Down

0 comments on commit 06e230f

Please sign in to comment.