code: def EnumKey(key, index):
    
    regenumkeyex = advapi32["RegEnumKeyExW"]
    regenumkeyex.restype = ctypes.c_long
    regenumkeyex.argtypes = [
        ctypes.c_void_p, ctypes.wintypes.DWORD, ctypes.c_wchar_p, LPDWORD,
        LPDWORD, ctypes.c_wchar_p, LPDWORD,
        ctypes.POINTER(FileTime)
    ]
  
    buf = ctypes.create_unicode_buffer(257)
    length = ctypes.wintypes.DWORD(257)
    rc = regenumkeyex(key.handle, index, ctypes.cast(buf, ctypes.c_wchar_p),
                      ctypes.byref(length), LPDWORD(), ctypes.c_wchar_p(),
                      LPDWORD(),
                      ctypes.POINTER(FileTime)())
    if rc != 0:
      raise ctypes.WinError(2)
  
    return ctypes.wstring_at(buf, length.value).rstrip(u"\x00")
docs: This calls the Windows RegEnumKeyEx function in a Unicode safe way.