Search code examples
c++delphiwindows-7sleepwindows-messages

How to make Windows go to sleep from app?


Im trying to make an app that can put windows 7 to sleep, I have been looking at WM_Messages, but cant seem to find one that does the jobb.

I can use ether C++ or Delphi to make the app if there it makes any difference.


Solution

  • Use SetSuspendState function which is in powrprof.dll:

    function SetSuspendState(hibernate, forcecritical, disablewakeevent: boolean): boolean;
        stdcall; external 'powrprof.dll' name 'SetSuspendState';
    
    SetSuspendState(false, false, false); // stand by
    SetSuspendState(true, false, false); // hibernate