Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

Cheers

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.

share|improve this question

1 Answer 1

Event 42 occurs too late (at the end of the process, no time to do anything useful) because it is intended as a "documentation" for subsequent diagnostics, not a notification before things happen. (I don't understand how could a MSFT moderator advice it?)

Unfortunately I haven't seen a working solution to your problem, but I'm sure that Windows does provide a before-event notification, although not in the Event log. This means that you have to create/use an always-running background application (~ a "daemon") that catches this pre-standby notification and then does whatever you like.
I'm not aware of an existing application that can do this, neither I know the relevant Windows APIs; but until a better answer is provided, here are some starting points that may help you in working out a solution:

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.