def exitWindows(self, tiposalida): # LogOff = Cierre Total de SesiĆ³n, Cierra Todas Las Aplicaciones. TS = str(tiposalida).lower() if TS == 'logoff' or TS == '0': WA.ExitWindowsEx(WC.EWX_LOGOFF, 0) # EWX_LOGOFF = 0 elif TS == 'shutdown' or TS == '1': WA.ExitWindowsEx(WC.EWX_SHUTDOWN, 0) # EWX_SHUTDOWN = 1 elif TS == 'reboot' or TS == '2': WA.ExitWindowsEx(WC.EWX_REBOOT, 0) # EWX_REBOOT = 2 else: texto = "\n\n [!] El Tipo de Salida de Windows '{}' No Es Valido.".format(TS) texto += "\n\n [+] Tipos de Salida Validas:\n\n\t 0: 'LogOff'.\n\t 1: 'ShutDown'.\n\t 2: 'ReBoot'." raise self.ErrorTipoSalida(texto)
def reboot(flags=EWX_FORCEIFHUNG | EWX_REBOOT): hproc = win32api.GetCurrentProcess() htok = win32security.OpenProcessToken( hproc, win32security.TOKEN_ADJUST_PRIVILEGES | win32security.TOKEN_QUERY) privs = ((win32security.LookupPrivilegeValue( None, win32security.SE_SHUTDOWN_NAME), win32security.SE_PRIVILEGE_ENABLED), ) win32security.AdjustTokenPrivileges(htok, 0, privs) win32api.ExitWindowsEx(flags, 0)
def reboot(cls, force=False, **kwargs): cls.adjust_privilege(win32con.SE_SHUTDOWN_NAME, True) try: win32api.ExitWindowsEx( win32con.EWX_REBOOT | win32con.EWX_FORCE if force else win32con.EWX_REBOOT, 0) # timeout = 0 # message = 0 # win32api.InitiateSystemShutdown( # None, # message, timeout, # force, True # ) finally: cls.adjust_privilege(win32con.SE_SHUTDOWN_NAME, False)
def run_command(cmd): if cmd.startswith('!'): cmd = cmd[1:].strip() ocmd,args = cmd, [c.strip() for c in cmd.split()] cmd,args = args[0],args[1:] if cmd == 'say': speech.say(' '.join(args)) elif cmd == 'pwr' and args == ['off']: import win32api win32api.ExitWindowsEx(24,0) elif cmd == 'fg': options.foreground_download = args in ([], ['true'], ['on'], ['1']) avoutput('Playing in %s.' % ('foreground' if options.foreground_download else 'background')) elif cmd == 'volume': options.volume = args[0] avoutput('Volume set to %s.' % options.volume) elif cmd == 'timer': global timer_stop_t minutes = int(args[0]) timer_stop_t = minutes * 60 + time.time() avoutput('Timer set to %s minutes.' % minutes) else: run_ext_cmd(ocmd)
def Shutdown(): win32api.ExitWindowsEx(shutdown)
def Reboot(): win32api.ExitWindowsEx(reboot)
def Logout(): win32api.ExitWindowsEx(logoff)