Ver Mensaje Individual
  #1  
Antiguo 23-07-2007
Avatar de cHackAll
[cHackAll] cHackAll is offline
Baneado?
 
Registrado: oct 2006
Posts: 2.159
Reputación: 20
cHackAll Va por buen camino
Pasar la PC a estado de Hibernación (hibernar)

Código Delphi [-]
uses Windows;
// Requiere:
//   Panel de Control -> Hibernación (Habilitar hibernación).
//   Al igual que ExitWindowsEx, requiere habilitar el privilegio SE_SHUTDOWN_NAME

var
 hToken, Dummy: Cardinal;
 Privileges: packed record
  Count: Cardinal;
  Luid: Int64;
  Attributes: Cardinal;
 end = (Count: 1; Attributes: SE_PRIVILEGE_ENABLED);

begin
 if OpenProcessToken(DWORD(-1), TOKEN_ADJUST_PRIVILEGES, hToken) then                                    // Abrimos la "ficha" de privilegios de nuestro proceso para hacer una modificación,
  begin
   LookupPrivilegeValue(nil, 'SeShutdownPrivilege', Privileges.Luid);                                    // Obtenemos el identificador del privilegio SE_SHUTDOWN_NAME
   AdjustTokenPrivileges(hToken, False, PTokenPrivileges(@Privileges)^, SizeOf(Privileges), nil, Dummy); // Habilitamos mediante el ID obtenido dicho privilegio...
   CloseHandle(hToken);                                                                                  // Cerramos el manejador
  end;

 SetSystemPowerState(False, True);                                                                       // Hibernamos...
end.

function SetSystemPowerState(fSuspend, fForce: LongBool): LongBool;
// Al estar fSuspend fijado como Verdadero suspenderá el equipo, caso contrario intentará hibernarlo.
// Cuando dicha API es llamada; envía a todas las ventanas e hilos que procesen mensajes, un mensaje notificando la accion tomada.
// Al estar fForce fijado como True, simplemente hace una notificación. Caso contrario solicita a "todos" el permiso de hacerlo.
Responder Con Cita