Renaud Bompuis
Renaud Bompuis

Reputation: 16806

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?

Upvotes: 6

Views: 5802

Answers (2)

dsrdakota
dsrdakota

Reputation: 2583

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.

Upvotes: 2

Leon Tayson
Leon Tayson

Reputation: 5011

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);

Upvotes: 10

Related Questions