Skip to content

Commit

Permalink
Handle error on invalid RegOpenKeyEx
Browse files Browse the repository at this point in the history
  • Loading branch information
elbakramer committed Feb 1, 2022
1 parent 19477f8 commit 55bfae6
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions koapy/utils/pywin32.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@ def IsPyIIDLike(value) -> TypeGuard[PyIIDLike]:
def GetTypelibSpecs(iid: PyIIDLike) -> List[TypelibSpec]:
specs: List[TypelibSpec] = []

key = win32api.RegOpenKey(win32con.HKEY_CLASSES_ROOT, "TypeLib")
key2 = win32api.RegOpenKey(key, str(iid))

for version, tlbdesc in EnumKeys(key2):
try:
key = win32api.RegOpenKey(win32con.HKEY_CLASSES_ROOT, "TypeLib")
key2 = win32api.RegOpenKey(key, str(iid))
except win32api.error:
enum_keys = []
else:
enum_keys = EnumKeys(key2)

for version, tlbdesc in enum_keys:
major_minor = version.split(".", 1)
if len(major_minor) < 2:
major_minor.append("0")
Expand Down

0 comments on commit 55bfae6

Please sign in to comment.