def OpenKey(key, sub_key):
 regopenkeyex = advapi32['RegOpenKeyExW']
 regopenkeyex.restype = ctypes.c_long
 regopenkeyex.argtypes = [ctypes.c_void_p, ctypes.c_wchar_p, ctypes.c_ulong, ctypes.c_ulong, ctypes.POINTER(ctypes.c_void_p)]
 new_key = KeyHandle()
 rc = regopenkeyex(key.handle, sub_key, 0, KEY_READ, ctypes.cast(ctypes.byref(new_key.handle), ctypes.POINTER(ctypes.c_void_p)))
 if (rc != ERROR_SUCCESS):
  raise ctypes.WinError(2)
 return new_key

def OpenKey ( key , sub_key ) : regopenkeyex = advapi32 [ 'RegOpenKeyExW' ] regopenkeyex . restype = ctypes . c_long regopenkeyex . argtypes = [ ctypes . c_void_p , ctypes . c_wchar_p , ctypes . c_ulong , ctypes . c_ulong , ctypes . POINTER ( ctypes . c_void_p ) ] new_key = KeyHandle ( ) rc = regopenkeyex ( key . handle , sub_key , 0 , KEY_READ , ctypes . cast ( ctypes . byref ( new_key . handle ) , ctypes . POINTER ( ctypes . c_void_p ) ) ) if ( rc != ERROR_SUCCESS ) : raise ctypes . WinError ( 2 ) return new_key
this calls the windows openkeyex function in a unicode safe way .