6

Possible Duplicate:
Is there any way to execute something when closing the laptop's lid?

I have a task that I want to run right before my computer sleeps or hibernates. Is there a way to schedule a task for this in the Windows 7 task scheduler?

The closest that I can see is for on locking the workstation, and this works as a surrogate, but I really don't want it to run on locking unless it is also sleeping/hibernating. Is there a way to schedule for an event like this?

0

2 Answers 2

5

I think your best bet is to configure the task to shut down or hibernate your computer when it finishes, and then start the task directly instead of stopping your computer. For example, write a batch file that runs the process and then shuts down the machine, and then run that batch file.

1
1

Found the answer in this question which sites a technet article. The Jist of it is that no the windows 7 is restricted to the list given, but you can attach a task to the sleep/hibernate/shutdown events through the task scheduler. Schedule with the trigger as a log event. For sleep use; Log= System, Source= Kernel-Power, Event ID= 42. And for shutdown System/Security/513.

3
  • Doesn't seem to work when the laptop power is not plugged in though.
    – anon
    Aug 27, 2014 at 19:28
  • Doesn't work properly for the Sleep event. It will run after the computer wakes up, not before it goes to sleep. Sep 8, 2017 at 11:23
  • Thanks! For Win10, use System/Kernel-Power/42 for sleep/hibernate and System/Kernel-Power/107 for wakeup. I think shutdown has changed to 4609 according to: andreafortuna.org/2019/06/12/… Mar 28, 2020 at 8:53

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