Note that this is different than the other questions I found (I did search), like: Is there any way to execute something when closing the laptop's lid?
I used the same trick of scheduling a task on event #42 (System, Kernel-Power, Event 42), but the problem is that the task - at least in my case - is not actually run before going to sleep. it seems the schedule executes it and goes to sleep at the same time. if the task takes longer to execute, then tough luck.
I have a batch file which does:
@echo off cd /d %~dp0 taskkill /t /im skype.exe sleep 2 taskkill /t /f /im skype.exe sleep 1
My task is not executed before going to sleep. The machine goes to sleep immediately as I can see the LEDs going off and hear the HDD click in less than 1 second, whereas I wanted it to hold of for 3 seconds before going to sleep.
It seems that tasks started by the scheduler are not holding off the sleep event -- and there are valid reasons for that (what if your task hangs?) -- but in my case, this is bummer!
Anyone knows of a way to make it work as intended above but being triggered by event 42?
NOTE: I know I can create a batch/program/task which first kills skype, waits, and then sends a Sleep event but I would like to be able to trigger it using Event 42. Other users sometime log onto this machine while Skype is running in a different account and they send it to sleep using the normal Sleep entry in the start menu, not a custom batch/program.
NOTE2 also tried with full paths for taskkill and sleep which are in Windows\System32. This kills Skype.exe then waits for 2 seconds then forcefully kills Skype.exe and then waits for another 1 second. This is due to a bug in Skype for Win 7 x64 which hangs Skype after waking up from Sleep. rather than waiting for Microsoft to fix this very old and frustrating and oh so overly-reported bug, I wanted to implement my own fix.