[SOLVED] How can I run a script (windows) BEFORE computer sleep?

harryoui

Reputable
Jun 25, 2015
93
0
4,660
I have a program that runs 24/7 but interrupts sleep if I don't close it beforehand. It sets the windows sleep to Away mode so that it can remain running, but I don't want it to run throughout sleep.

It's pretty easy to run the program at startup with Task Scheduler or by placing a shortcut in shell:startup folder, but Task Scheduler doesn't include any triggers for Computer Sleep.

How can I quit the program before my computer goes into sleep (specifically before it can interrupt sleep)?
 
Solution
I suspect you would Run a scheduled task when event 42 (entering sleep) triggers that begins by waiting or forcing sleep to wait for the batch to finish and at the end of the batch issue or resume sleep.
Sep 21, 2020
1
0
10
Hi there
I'm trying to solve the issune using the solution suggested here.
it isn't working so far, I mean I'm running a scheduled task that triggers the event 42 (system / kernel-power). the problem is that the batch enters in action right after windows 10 wakes up from sleeping instead of to execute the batch right before the sleep.
also the task history reports that the action is executet once the system wakes up (I realise it reading the time which coincide with the wake up time.
Seems that the event 42 read too late.
Hope you can help me. thanks