-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; if GetPwrCapabilities(SystemPowerCapabilities) then
if not SystemPowerCapabilities[6] then
Result := 3 else if not SystemPowerCapabilities[8] and (CallNtPowerInformation(10, @Result, 1, nil, 0) <> 0) then
Result := 1 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 else if not SetSuspendState(True, ForceCritical, True) then Result := 4 else
Result := 0;
CloseHandle(hToken);
end;
end;
Regards :D