954,529 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?

Check if Hibernation or Suspend is allowed

0
By Lord Soth on Mar 18th, 2006 4:47 pm

Works on W2K and above

function HibernateAllowed: Boolean;
type
  TIsPwrHibernateAllowed = function: Boolean;
  stdcall;
var
  hPowrprof: HMODULE;
  IsPwrHibernateAllowed: TIsPwrHibernateAllowed;
begin
  Result := False;
  if IsNT4Or95 then Exit;
  hPowrprof := LoadLibrary('powrprof.dll');
  if hPowrprof <> 0 then
  begin
    try
      @IsPwrHibernateAllowed := GetProcAddress(hPowrprof, 'IsPwrHibernateAllowed');
      if @IsPwrHibernateAllowed <> nil then
      begin
        Result := IsPwrHibernateAllowed;
      end;
    finally
      FreeLibrary(hPowrprof);
    end;
  end;
end;


function SuspendAllowed: Boolean;
type
  TIsPwrSuspendAllowed = function: Boolean;
  stdcall;
var
  hPowrprof: HMODULE;
  IsPwrSuspendAllowed: TIsPwrSuspendAllowed;
begin
  Result := False;
  hPowrprof := LoadLibrary('powrprof.dll');
  if hPowrprof <> 0 then
  begin
    try
      @IsPwrSuspendAllowed := GetProcAddress(hPowrprof, 'IsPwrSuspendAllowed');
      if @IsPwrSuspendAllowed <> nil then
      begin
        Result := IsPwrSuspendAllowed;
      end;
    finally
      FreeLibrary(hPowrprof);
    end;
  end;
end;

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You