def request_privileges(self, state, *privileges): try: with win32.OpenProcessToken( win32.GetCurrentProcess(), win32.TOKEN_ADJUST_PRIVILEGES) as hToken: NewState = ((priv, state) for priv in privileges) win32.AdjustTokenPrivileges(hToken, NewState) except Exception, e: print e return False
def adjust_privileges(state, privileges): """ Requests or drops privileges. @type state: bool @param state: C{True} to request, C{False} to drop. @type privileges: list(int) @param privileges: Privileges to request or drop. @raise WindowsError: Raises an exception on error. """ with win32.OpenProcessToken(win32.GetCurrentProcess(), win32.TOKEN_ADJUST_PRIVILEGES) as hToken: NewState = ((priv, state) for priv in privileges) win32.AdjustTokenPrivileges(hToken, NewState)