Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically bring a laptop into Sleep mode

What API or tools can I use to query the capabilities of the system and choose the most appropriate on for putting the PC to Sleep, Hibernate or shutdown mode?

Thanks for any pointers.

like image 270
Renaud Bompuis Avatar asked Dec 29 '08 16:12

Renaud Bompuis


People also ask

Is there a command to put your PC to sleep?

2. The Alt + F4 Sleep Mode Shortcut. As you might know, pressing Alt + F4 closes the current app window, just like clicking the X in the top-right corner of a program. However, if you don't have a window currently selected, you can use Alt + F4 as a shortcut for sleep in Windows 10.

How do I enable sleep mode in BIOS?

In the BIOS menu, select "Power Management" then "Block Sleep". Take the check mark out of "Block Sleep" then click "Apply". When you reboot, you will have the option to sleep.


2 Answers

Look at SystemInformation.PowerStatus, then you can call Application.SetSuspendState to put the PC to Sleep or Hibernate like:

Application.SetSuspendState(PowerState.Hibernate, true, true);
like image 134
Leon Tayson Avatar answered Nov 15 '22 04:11

Leon Tayson


You could use the API:

Declare Function SetSuspendState Lib "PowrProf" (ByVal Hibernate As Integer, ByVal ForceCritical As Integer, ByVal DisableWakeEvent As Integer) As Integer

SetSuspendState(0, 0, 0) 'Sleep without forcing and ?no? wake events
SetSuspendState(1, 0, 0) 'Hibernate without forcing and ?no? wake events

Set Hibernate to 1(True) to Hibernate or 0(False) to Sleep.

See the API here.

like image 36
dsrdakota Avatar answered Nov 15 '22 02:11

dsrdakota