def rename_regkey(skey, ssubkey, dsubkey):
 res_handle = HANDLE()
 options = DWORD(0)
 res = RegOpenKeyExW(skey, ssubkey, options, _winreg.KEY_ALL_ACCESS, byref(res_handle))
 if (not res):
  bsize = c_ushort((len(dsubkey) * 2))
  us = UNICODE_STRING()
  us.Buffer = c_wchar_p(dsubkey)
  us.Length = bsize
  us.MaximumLength = bsize
  res = NtRenameKey(res_handle, pointer(us))
  if res:
   log.warning('Error renaming %s\\%s to %s (0x%x)', skey, ssubkey, dsubkey, (res % (2 ** 32)))
 if res_handle:
  RegCloseKey(res_handle)

def rename_regkey ( skey , ssubkey , dsubkey ) : res_handle = HANDLE ( ) options = DWORD ( 0 ) res = RegOpenKeyExW ( skey , ssubkey , options , _winreg . KEY_ALL_ACCESS , byref ( res_handle ) ) if ( not res ) : bsize = c_ushort ( ( len ( dsubkey ) * 2 ) ) us = UNICODE_STRING ( ) us . Buffer = c_wchar_p ( dsubkey ) us . Length = bsize us . MaximumLength = bsize res = NtRenameKey ( res_handle , pointer ( us ) ) if res : log . warning ( 'Error renaming %s\\%s to %s (0x%x)' , skey , ssubkey , dsubkey , ( res % ( 2 ** 32 ) ) ) if res_handle : RegCloseKey ( res_handle )
rename an entire tree of values in the registry .