locked
Run a batch file before sleeping RRS feed

  • Question

  •  

    I have a hardware issue with a touchscreen that is preventing a new Vista Home Premium SP1 system from sleeping. The system will start to sleep, then jolt awake again just after the screen powers down. The powercfg -lastwake reported a 'USB Root Hub' was causing the system to wake up. Without the touchscreen's USB connected, the system will sleep and wake with no problems.

     

    I first tried obtaining the latest drivers for the touch screen, but installing these has had no effect.

     

    I tried leaving the touch screen connected, and disabling the devices in Device Manager. After some experimentation, this worked - although I need to disable 4 devices (touch screen, serial port, serial port converter, usb root hub). I was then able to write a pair of batch files which use devcon to disable and enable these devices easily.

     

    I then setup a pair of scheduled tasks to run the 'disabletouch' batch file when kernel-power event 41 occurs (the system is entering sleep), and 'enabletouch' on 'windows power troubleshooter' event 1.

     

    Sadly, the disabletouch batch file does not get time to start before the system enters sleep mode, and so the sleep fails and then system jerks awake after a few seconds as before. I then see both batch files executing concurrently. If disable the 'disabletouch' task and run it manually before pressing the sleep button everything works fine.

     

    Can anyone recommend a way of ensuring the disabletouch batch file can run to completion in between the sleep button being pressed and the system entering sleep mode (or provide any other suggestions)?

    Wednesday, April 2, 2008 3:14 PM

All replies

  • I"m no expert here, so this is my funky suggestion...

     

    first, my log shows power event 42 instead of 41 for system entering sleep, if that makes any difference.

     

    Since it wakes right back up, as you long as you intercept the event, you can force it right back to sleep. Just put a sleep command at the end of your batch file. There are freebie programs with names like standby.exe or suspend.exe that'll do the trick.

     

    The sequence would be

     

    Sleep event fires

    event is logged

    system sleeps

    USB interrupt causes it to wake

    scheduler catches the logged sleep event

    custom batch is executed

       USB device is disabled

       system forced back to sleep

     

    There is a powercfg option in Vista to permit programs to to deny a sleep query, but you'd need to write a monitor program for that... not a simple batch file. And, as far as I can see, the sleep button does not send a query first anyway.

     

    Tuesday, May 13, 2008 7:16 PM
  • Did you find any solution to this?

    I have a very similar problem.

    I have to run devcon to disable a wifi-device before windows goes to sleep, otherwhise the wifi-device won't work when i resume windows.
    Doing this manually ever time is getting really annoying so I tried to automate this in the task scheduler. The problem is that running devcon takes 3 seconds, putting the computer to sleeps only takes one. I need a way to halt the sleep-process until devcon is complete.
    Saturday, March 14, 2009 5:22 PM