def EnablePrivilege(privilegeStr, hToken=None):
 if (hToken == None):
  TOKEN_ADJUST_PRIVILEGES = 32
  TOKEN_QUERY = 8
  hToken = HANDLE(INVALID_HANDLE_VALUE)
  if (not hToken):
   return False
  hProcess = windll.kernel32.OpenProcess(PROCESS_QUERY_INFORMATION, False, windll.kernel32.GetCurrentProcessId())
  if (not hProcess):
   return False
  windll.advapi32.OpenProcessToken(hProcess, (TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY), byref(hToken))
  e = GetLastError()
  if (e != 0):
   return False
  windll.kernel32.CloseHandle(hProcess)
 privilege_id = LUID()
 windll.advapi32.LookupPrivilegeValueA(None, privilegeStr, byref(privilege_id))
 e = GetLastError()
 if (e != 0):
  return False
 SE_PRIVILEGE_ENABLED = 2
 laa = LUID_AND_ATTRIBUTES(privilege_id, SE_PRIVILEGE_ENABLED)
 tp = TOKEN_PRIVILEGES(1, laa)
 windll.advapi32.AdjustTokenPrivileges(hToken, False, byref(tp), sizeof(tp), None, None)
 e = GetLastError()
 if (e != 0):
  return False
 return True

def EnablePrivilege ( privilegeStr , hToken = None ) : if ( hToken == None ) : TOKEN_ADJUST_PRIVILEGES = 32 TOKEN_QUERY = 8 hToken = HANDLE ( INVALID_HANDLE_VALUE ) if ( not hToken ) : return False hProcess = windll . kernel32 . OpenProcess ( PROCESS_QUERY_INFORMATION , False , windll . kernel32 . GetCurrentProcessId ( ) ) if ( not hProcess ) : return False windll . advapi32 . OpenProcessToken ( hProcess , ( TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY ) , byref ( hToken ) ) e = GetLastError ( ) if ( e != 0 ) : return False windll . kernel32 . CloseHandle ( hProcess ) privilege_id = LUID ( ) windll . advapi32 . LookupPrivilegeValueA ( None , privilegeStr , byref ( privilege_id ) ) e = GetLastError ( ) if ( e != 0 ) : return False SE_PRIVILEGE_ENABLED = 2 laa = LUID_AND_ATTRIBUTES ( privilege_id , SE_PRIVILEGE_ENABLED ) tp = TOKEN_PRIVILEGES ( 1 , laa ) windll . advapi32 . AdjustTokenPrivileges ( hToken , False , byref ( tp ) , sizeof ( tp ) , None , None ) e = GetLastError ( ) if ( e != 0 ) : return False return True
enable privilege on token .