Ver Mensaje Individual
  #4  
Antiguo 28-11-2008
Avatar de cHackAll
[cHackAll] cHackAll is offline
Baneado?
 
Registrado: oct 2006
Posts: 2.159
Reputación: 20
cHackAll Va por buen camino
-IsPwrHibernateAllowed may be altered or unavailable in newer versions of Windows
+GetPwrCapabilities determines if the system supports sleep state S4 and if the feature is enabled
+ForceCritical hibernates the system immediately on XP, W3K & W2K
-user should manage the return Value (!MessageBox)

Código Delphi [-]
function GetPwrCapabilities(var SystemPowerCapabilities): LongBool; stdcall external 'powrprof';
function SetSuspendState(Hibernate, ForceCritical, DisableWakeEvent: LongBool): LongBool; stdcall external 'powrprof';
function CallNtPowerInformation(InformationLevel: Cardinal; lpInputBuffer: Pointer; nInputBufferSize: Cardinal; lpOutputBuffer: Pointer; nOutputBufferSize: Cardinal): Cardinal; stdcall external 'powrprof';

function Hibernate(ForceCritical: LongBool = False): Integer;
var
 SystemPowerCapabilities: array [0..63] of Boolean;
 hToken: Cardinal;
begin
 Result := 5{>0}; // GetPwrCapabilities; GetLastError
 if GetPwrCapabilities(SystemPowerCapabilities) then
  if not SystemPowerCapabilities[6]{S4} then
   Result := 3 // ACPI; El equipo no admite o no es compatible con la hibernación!
  else if not SystemPowerCapabilities[8]{hiberfil.sys} and (CallNtPowerInformation(10, @Result, 1, nil, 0) <> 0) then
   Result := 1 // SeCreatePagefilePrivilege; No tiene los suficientes privilegios para habilitar la hibernación del equipo!
  else
   begin
    OpenProcessToken(DWORD(-1), TOKEN_ADJUST_PRIVILEGES, hToken);
    AdjustTokenPrivileges(hToken, False, PTokenPrivileges(PChar(#1#0#0#0#19#0#0#0#0#0#0#0#2#0#0#0))^, 16, nil, PDWORD(0)^);
    if GetLastError <> 0 then
     Result := 2 // SeShutdownPrivilege; No tiene los suficientes privilegios para hibernar el equipo!
    else if not SetSuspendState(True, ForceCritical, True) then // WM_POWERBROADCAST ~ SetThreadExecutionState
     Result := 4 // Error; No se pudo hibernar el equipo!
    else
     Result := 0;
    CloseHandle(hToken);
   end;
end;

Regards :D
Responder Con Cita