def set_owner(obj_name, principal, obj_type='file'):
 sid = get_sid(principal)
 flags = Flags()
 new_privs = set()
 luid = win32security.LookupPrivilegeValue('', 'SeTakeOwnershipPrivilege')
 new_privs.add((luid, win32con.SE_PRIVILEGE_ENABLED))
 luid = win32security.LookupPrivilegeValue('', 'SeRestorePrivilege')
 new_privs.add((luid, win32con.SE_PRIVILEGE_ENABLED))
 p_handle = win32api.GetCurrentProcess()
 t_handle = win32security.OpenProcessToken(p_handle, (win32security.TOKEN_ALL_ACCESS | win32con.TOKEN_ADJUST_PRIVILEGES))
 win32security.AdjustTokenPrivileges(t_handle, 0, new_privs)
 try:
  win32security.SetNamedSecurityInfo(obj_name, flags.obj_type[obj_type], flags.element['owner'], sid, None, None, None)
 except pywintypes.error as exc:
  log.debug('Failed to make {0} the owner: {1}'.format(principal, exc[2]))
  raise CommandExecutionError('Failed to set owner: {0}'.format(exc[2]))
 return True

def set_owner ( obj_name , principal , obj_type = 'file' ) : sid = get_sid ( principal ) flags = Flags ( ) new_privs = set ( ) luid = win32security . LookupPrivilegeValue ( '' , 'SeTakeOwnershipPrivilege' ) new_privs . add ( ( luid , win32con . SE_PRIVILEGE_ENABLED ) ) luid = win32security . LookupPrivilegeValue ( '' , 'SeRestorePrivilege' ) new_privs . add ( ( luid , win32con . SE_PRIVILEGE_ENABLED ) ) p_handle = win32api . GetCurrentProcess ( ) t_handle = win32security . OpenProcessToken ( p_handle , ( win32security . TOKEN_ALL_ACCESS | win32con . TOKEN_ADJUST_PRIVILEGES ) ) win32security . AdjustTokenPrivileges ( t_handle , 0 , new_privs ) try : win32security . SetNamedSecurityInfo ( obj_name , flags . obj_type [ obj_type ] , flags . element [ 'owner' ] , sid , None , None , None ) except pywintypes . error as exc : log . debug ( 'Failed to make {0} the owner: {1}' . format ( principal , exc [ 2 ] ) ) raise CommandExecutionError ( 'Failed to set owner: {0}' . format ( exc [ 2 ] ) ) return True
set the owner of an object .