Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Otros temas > Trucos
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Los mejores trucos

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 28-11-2008
Avatar de cHackAll
[cHackAll] cHackAll is offline
Baneado?
 
Registrado: oct 2006
Posts: 2.159
Poder: 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
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro


La franja horaria es GMT +2. Ahora son las 04:52:35.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi