Run scheduled task or a GPO when Win7 SleepMode is triggered?


  1. Posts : 6
    Windows 7 Ultimate x64
       #1

    Run scheduled task or a GPO when Win7 SleepMode is triggered?


    Hello all, I'd like to launch a custom batch file when my computer goes into sleep mode. I would like to launch this batch through a GPO or task scheduler.

    I've tested using task scheduler and the power event ID for sleep mode but it seems the event triggers too late for the application to run and the computer just continues into sleep mode.
    I could create a scheduled task to trigger a minute before the idle time-out for sleep mode but this doesn't help if I actively put the computer into sleep mode.

    Does anyone know of a way to do this?
      My Computer


  2. Posts : 6,330
    Multi-Boot W7_Pro_x64 W8.1_Pro_x64 W10_Pro_x64 +Linux_VMs +Chromium_VM
       #2

    Does your task need to run before going to Sleep, or would it be ok to run it on Wakeup?
      My Computer


  3. Posts : 6
    Windows 7 Ultimate x64
    Thread Starter
       #3

    Thanks for the quick response!

    The task needs to run before the machine sleeps.
    I'm going to test creating the task on system lock and see if it triggers while going into sleep mode.
    On second thought, I actually don't want this batch file to run during lock but only when entering sleep-mode.
    Last edited by idecz; 09 Jul 2012 at 20:13.
      My Computer


  4. Posts : 6
    Windows 7 Ultimate x64
    Thread Starter
       #4

    Okay through testing I've discovered that using the event id for sleep-mode won't work because it is triggered too late for task scheduler, in fact task scheduler will read the event id after waking up and then trigger.

    I was able to get task scheduler to trigger before sleep-mode based on idle timeout but this doesn't help when a user actively enters sleep-mode.

    Going to check around on technet and try some experimenting.
      My Computer


  5. Posts : 6,330
    Multi-Boot W7_Pro_x64 W8.1_Pro_x64 W10_Pro_x64 +Linux_VMs +Chromium_VM
       #5

    Hi idecz,

    It sounds like you know what you are doing and why.
    I'm following this to learn from you :)

    I wondered if the task would start after the wake-up, and you answered that with
    "will read the event id after waking up and then trigger".

    Can I ask, why do you need the task to run before sleep?
    I'm a programmer, so i can understand there is a need ... disconnect from resources, logoff network accounts, kill a kiosc session, ... etc.

    I'm just wondering if there might not be a better/easier/safer way to do what you need to do than using task scheduler.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 07:24.
Find Us