0

I have created 2 tasks for sleep and wake following this guide: https://www.groovypost.com/howto/schedule-wake-sleep-windows-automatically/

If I run the sleep task independently PC goes to sleep and wakes by mouse move event.

If I schedule the waking task and set the PC to sleep keyboard button it will wake up by schedule task.

So tasks are working great independently but not in a task event chain.

What I have tried:

  • disable hibernation by powercfg -h off
  • allowed wake timers (set to Enabled) in Settings -> Power Options
  • enabled everything in BIOS related to event timers and wakings
  • used pauses between sleep and wake tasks more than 5 minutes
  • shaman dances with a tambourine

Additional screenshots:

enter image description here

Downloadable software is not an option. The same behavior on PC and laptop. Struggling is continued for 2 days so far...

1 Answer 1

0
$script = '$signature = @"
[DllImport("powrprof.dll")]
public static extern bool SetSuspendState(bool Hibernate,bool ForceCritical,bool DisableWakeEvent);
"@
$func = Add-Type -memberDefinition $signature -namespace "Win32Functions" -name "SetSuspendStateFunction" -passThru
$func::SetSuspendState($false,$true,$false)'

$bytes = [System.Text.Encoding]::Unicode.GetBytes($script)
$encodedCommand = [Convert]::ToBase64String($bytes)

$action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-encodedCommand $encodedCommand"

$trigger = New-ScheduledTaskTrigger -Daily -DaysInterval 1 -At 16:43
Register-ScheduledTask -TaskName "Sleep" -Action $action -Trigger $trigger -Force

$action = New-ScheduledTaskAction -Execute "cmd.exe" -Argument "/c echo hello"
$settings = New-ScheduledTaskSettingsSet -WakeToRun
$trigger = New-ScheduledTaskTrigger -Daily -DaysInterval 1 -At 16:44
Register-ScheduledTask -TaskName "Wake" -Action $action -Settings $settings -Trigger $trigger -Force

Works like a charm :)

Also DO NOT USE RUNDLL32 because

Rundll32 can only call functions from a DLL that are explicitly written to be called by Rundll32.

https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/rundll32#remarks

1
  • Hi. Sorry for disturbing the dead thread, but - could you explain your script?
    – Mike
    Commented Jun 25 at 11:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .