0
After giving up for months i'd like to revisit the idea that seems so incredibly simple. I want to have a script that wakes up my monitors after they were send to sleep. I tried almost any approach i can think of, please someone save me from adopting a dog that fetches a bone shaped bluetooth mouse wiggling it in the process (yes, i'm that desperate)
What i did so far:
1) Installing OpenSSH on the remote Win10 Machine (works)
2) Getting the interactive Windows session to have authority over the actual session:
FOR /F "usebackq tokens=4" %s IN (
tasklist /nh /fo table /fi "imagename eq explorer.exe"
) DO ...
3a) Starting one of the many keep windows awake programs. Those don't work because they are never launched by psexec or powershell. Or at least if they run they fail to display and do nothing. That's for any process i try to start.
3b) Use SendMessage like i do for the sending it to sleep:
psexec -accepteula -nobanner -d -i %%s -w "%windir%" powershell (Add-Type '[DllImport(\"user32.dll\")]^public static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);' -Name a -Pas)::SendMessage(-1,0x0112,0xF170,-1) Passing 2 as the last parameter works perfect to turn the monitor off. Passing anything else (e.g. -1 for ON) does nothing.
3c) Now desperate i try to do a mouse wiggle/keypress simulation etc.:
FOR /F "usebackq tokens=4" %%s IN (
tasklist /nh /fo table /fi "imagename eq explorer.exe"
) DO psexec -accepteula -nobanner -d -i %%s -w "%windir%" powershell (Add-Type '[DllImport(\"user32.dll\")]^public static extern void mouse_event(uint dwFlags, int dx, int dy, uint dwData, int dwExtraInfo);' -Name user32 -PassThru)::mouse_event(1,40,0,0,0) Works locally executed with elevated rights. Does pop up powershell briefly when used with SSH. Does not do any mouse wiggling.
3d) using good old nircmd.exe monitor off or similar dedicated turn monitor on utilities. Same result as 3a)
Many of the linked threads have supposed solutions, but not of them works for me. The only difference i can glance from executing the script locally vs via ssh is that there is a output of something like
powershell started on with process ID xxxxx
Other than that i have no way of telling what is going on. I put an echo 0 at the end of the scripts to check if it was executed or not. It always gives me the 0. Anyone got an idea what i am missing? Especially 3b) is weird to me since it works for sending the monitor to sleep.
Thank you very much. This does exactly what i was looking for. Just for clarification, when you say "wake the computer" you are not referring to a power state in this case, right? What magic does the parameter 0x03 do? I couldn't find it in the SetThreadExecutionState docs. – narfelchen – 2019-11-11T09:38:16.410
1@narfelchen when displays are turned off the computer is automatically set to
idle
state. Thesetthreadexecutionstate
call basically tells the computer it is no longer idle. This effectively wakes it. – shawn – 2019-11-11T16:07:43.597