2

An old problem, maybe (?) resolved for older Windows version, but not for Windows 10!

The solutions proposed in old discussions (... SetSuspendState with parameters 0,1,0 (or Sleep), with or without prior hibernate off ...) dont work on Windows 10 systems; at least not on all: the initiated mode is mostly hibernate, not sleep.

What I found out: In older Windows versions there was something like this in the Registry: [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\sleep\command] @="rundll32.exe powrprof.dll,SetSuspendState Sleep" This obviously was the sleep command. At least on my Windows 10 PCs there is no such entry!

Somebody here with new answers?

================== EDITED: After this my OP I discovered that this is not a Windows 10 issue, it is a Surface 3 issue, related to the power option used on Surface 3 as Sleep mode:

The Sleep mode used by Surface 3 seems to be "Modern Standby" = "S0 Low Power Idle" = "Connected Network Standby". (Not the usual S3 Sleep mode!!!)

The commands using SetSuspendState seems to be unable at all to initiate the Sleep mode on a Surface 3.

A new wording for my question: All what I would like to have is a command which does the same as the Power button on a Surface 3 which is set to "power-button action = Sleep", or as the Sleep button on an external (USB) keyboard when Surface 3 is set to "sleep-button action = Sleep".

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
newbieforever
  • 217
  • 1
  • 4
  • 15
  • EDITED ... A new wording for my question: All what I would like to have is a command which does the same as the Power button on a Surface 3 which is set to "power-button action = Sleep", or as the Sleep button on an external (USB) keyboard when Surface 3 is set to "sleep-button action = Sleep". – newbieforever Dec 29 '16 at 09:20
  • Are you sure the power button / sleep button is actually putting the system in S3 and not "modern standby"? How do you tell the difference? – Harry Johnston Dec 29 '16 at 20:22
  • @Harry Johnston: ???The other way round!!! And I can know this because powercfg /a says that S3 isa not supported on Surface 3. – newbieforever Dec 29 '16 at 20:42
  • So you mean that you want to reach "modern standby" but SetSuspendState is resulting in hibernation aka S4? – Harry Johnston Dec 29 '16 at 20:59
  • A new attempt: (1) Primarily I would like to have a command which does the same as pressing the power button on each individual computer (i.e. the command does exactly the action which on the individual PC is set in Power Options as power-button action). (2) But forget this excessive question!!! (3) On my Surface 3 I set "Sleep" for the power-buttton and sleep-button action. (4) Surface 3 obviously uses "Modern Standby" in this case if I press the power or sleep button. (5) I simply would like to have a command which does the same on my Surface 3 as pressing the power or sleep button. – newbieforever Dec 30 '16 at 14:19

2 Answers2

1

I found this new solution on Programmatically enter Connected Standby in C#

On my Surface 3, I am able now to activate the Sleep mode ("Modern Standby" = "S0 Low Power Idle" = "Connected Network Standby") by a command which turns off the monitor. In Autohotkey this is simply the line:

SendMessage, 0x112, 0xF170, 2,, Program Manager

I can see in the sleepstudy-report.html (created by powercfg /sleepstudy) that really "Modern Standby" is entered by this.

newbieforever
  • 217
  • 1
  • 4
  • 15
0

I haven't found a satisfactory answer to this question on the internet, my current solution is simulating key pressing.

In Python, I use the pyautogui module. Here's my codes:

import pyautogui

pyautogui.press("win")
pyautogui.press("tab")
pyautogui.press("tab")
pyautogui.press("tab")
pyautogui.press("enter")
pyautogui.press("tab")
pyautogui.press("enter")
sfeng
  • 46
  • 3
  • Steps will be diffrent in diffrent based on os. – Hiren Patel Nov 18 '22 at 11:12
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 18 '22 at 11:12
  • Please check this, it will be helpfull to you. [https://stackoverflow.com/a/37009921/9787228] – Hiren Patel Nov 18 '22 at 11:14