Share via

How to programatically trigger "Modern" standby (desktop app)

James Clark 6 Reputation points
2022-04-12T14:13:59.123+00:00

Traditionally, desktop apps could use the SetSuspendState() API to suspend (S1-S3).

However, this no longer works on systems that support "modern" standby and fails with ERROR_NOT_SUPPORTED.

A workaround is to turn off the display. This triggers "modern" standby but cannot be (easily) done from a service application due to session 0 isolation.

What is the best way to trigger "modern" standby from a service?

Windows development | Windows API - Win32
0 comments No comments

1 answer

Sort by: Most helpful
  1. Jeanine Zhang-MSFT 11,356 Reputation points Microsoft External Staff
    2022-04-13T06:18:53.363+00:00

    Hi,

    Welcome to Microsoft Q&A!

    Modern Standby consists of multiple hardware and software power modes, all of which occur with the screen turned off.

    I suggest you could try to use the SC_MONITORPOWER parameter for the WM_SYSCOMMAND message to turn off the monitor:

    SendMessage(handle, WM_SYSCOMMAND, SC_MONITORPOWER, 2);  
    

    The argument 2 for the fourth parameter turns the monitor off.

    You could refer to the Doc:
    https://learn.microsoft.com/en-gb/windows/win32/menurc/wm-syscommand?redirectedfrom=MSDN

    Best Regards,

    Jeanine


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.