[SOLVED] Wake Up Task won't work if PC put into sleep mode manually

pjfarr

Distinguished
Jul 23, 2015
7
0
18,510
Many times I use a keyboard shortcut I made to manually put my PC to sleep if I know I'm done with it for the day. The CMD embedded in the shortcut is the popular:
Code:
C:\Windows\System32\rundll32.exe powrprof.dll,SetSuspendState sleep.
It works, no problem. The thing is I have a task scheduled to wake my PC every morning at 4:30. But the only time this task seems to work is when the PC went into sleep mode automatically or via the Start Menu option. If I use the keyboard shortcut to put it to sleep the wake up task doesn't work the next morning. Some have suggested that the code in that keyboard command puts the PC in hibernate mode even though it clearly says "sleep" but I have hibernate mode disabled.

Any clues...?
Windows 10 is up to date.
 
Solution
rundll32 shouldnt be used to call random dll functions
for setsuspendstate....see remarks on this page
https://docs.microsoft.com/en-us/wi...-powrprof-setsuspendstate?redirectedfrom=MSDN

use this inside batch file:
Code:
@echo off
powershell.exe -C "$m='[DllImport(\"Powrprof.dll\",SetLastError=true)]static extern bool SetSuspendState(bool hibernate,bool forceCritical,bool disableWakeEvent);public static void PowerSleep(){SetSuspendState(false,false,false); }';add-type -name Import -member $m -namespace Dll; [Dll.Import]::PowerSleep();"
rundll32 shouldnt be used to call random dll functions
for setsuspendstate....see remarks on this page
https://docs.microsoft.com/en-us/wi...-powrprof-setsuspendstate?redirectedfrom=MSDN

use this inside batch file:
Code:
@echo off
powershell.exe -C "$m='[DllImport(\"Powrprof.dll\",SetLastError=true)]static extern bool SetSuspendState(bool hibernate,bool forceCritical,bool disableWakeEvent);public static void PowerSleep(){SetSuspendState(false,false,false); }';add-type -name Import -member $m -namespace Dll; [Dll.Import]::PowerSleep();"
 
Last edited:
Solution