Sleep Modes with Modern Standby on new PCs (win32 api)

491 Views Asked by At

I have a new PC that doesn't support S3 sleep, only S0. I am working on a small application to initiate various modes of sleep on command. When I run powercfg -a, it tells me the only available sleep mode is S0 (I have hibernate disabled as I don't want to use it because it takes to long to wake).

I have found the following WIN32 API function that will cause the PC to go into the same sleep state as pressing Start, Shutdown, Sleep:

SendMessage(application_handle, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_OFF);

This turns off the monitor and keyboard backlight. The PC's power light stays on and the fan sounds like it is still running, but my understanding is that this is part of the new "modern standby" which doesn't actually put the computer to sleep (where the fan shuts off and the power light blinks).

I have also set Windows Settings, Power settings as follows:

  • Turn off monitor after [5 minutes]
  • Put my device to sleep after [Never]

The reason I do this is if you allow the computer to go to "sleep" after some inactive period, Task Scheduler no longer runs tasks like overnight backups, etc. Leaving the sleep setting set to "never" allows Task Scheduler to run those tasks properly.

So these settings turn of the monitor by putting the computer into a state that is different than what happens when you use: Start, Shutdown, Sleep.

It would seem logical at first glance that:

SendMessage(application_handle, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_OFF);

would only turn off the monitor, similar to the 5 minute timeout, but instead, it seems to more closely emulate the kind of sleep caused by Start, Shutdown, Sleep on my PC.

Does anyone know a programmatic (i.e. Win32 API) way to emulate the monitor turning off that doesn't go into the deeper sleep state? Basically, I'm looking for a way to programmatically initiate the sleep mode that Windows initiates when the Windows Power settings above trigger after 5 minutes of inactivity (just shutting off the monitor).

Thanks!

1

There are 1 best solutions below

0
YangXiaoPo-MSFT On

According to Entry to Modern Standby, there is no Win32 API to let Windows enter Modern Standby.

Modern Standby starts when the user causes the system to enter sleep (e.g user pressing the power button, closing the lid, idling out, or selecting Sleep from the power button in the Windows Start menu).

And according to Display, sleep, and hibernate idle timers, you can use SC_MONITORPOWER to Turn off the display but Modern Standby means putting the computer to sleep with the display being immediately powered down.

Timer On a traditional PC On a modern standby system Notes
Dim the display This time-out is no longer supported starting with Windows 8.1. In Windows 10, the display is automatically dimmed 10 seconds before it is turned off. This time-out is no longer supported starting with Windows 8.1. In Windows 10, the display is automatically dimmed 10 seconds before it is turned off.
Turn off the display When this time-out occurs, the display immediately turns off. However, the system continues to run and all applications continue to operate normally as if the display was powered on. When this time-out occurs, the display immediately turns off. However, the system continues to run and all applications continue to operate normally as if the display was powered on. There is a 5-second grace period between when the display turns off and when the screen off notification is fired.
Put the computer to sleep When this time-out occurs, the system immediately enters the ACPI Sleep (S3) state. All applications stop execution because all processors will be powered off. When this time-out occurs, the system enters modern standby and the display is immediately powered down. Then the system steps through the preparation phases described in Prepare software for modern sleep.
Hibernate after When this timer expires, the system wakes from ACPI Sleep (S3) and immediately enters ACPI Hibernate (S4) to save power. This time-out is not recommended for modern standby systems. Modern standby has the intelligence to manage hibernate internally and setting a separate hibernate timeout can result in a loss of some features.