Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.

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

09 Jul 2012   #1

Windows 7 Ultimate x64
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 System SpecsSystem Spec
09 Jul 2012   #2

Multi-Boot W7_Pro_x64 W8.1_Pro_x64 W10_Pro_x64

Does your task need to run before going to Sleep, or would it be ok to run it on Wakeup?
My System SpecsSystem Spec
09 Jul 2012   #3

Windows 7 Ultimate x64

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.
My System SpecsSystem Spec

12 Jul 2012   #4

Windows 7 Ultimate x64

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 System SpecsSystem Spec
12 Jul 2012   #5

Multi-Boot W7_Pro_x64 W8.1_Pro_x64 W10_Pro_x64

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 System SpecsSystem Spec

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

Thread Tools

Similar help and support threads
Thread Forum
eruNT lives again, on Win7/Vista -- without 'Scheduled Task' UAC-hack
This isn't a request for help, but just thanks for all the good advice I've received here. This (widely acclaimed) Windows Registry backup utility restores the security feature Microsoft discontinued with Windows 98SE and Windows ME: the ability to retain full daily automatic backups of a...
Backup and Restore
Scheduled Task: Configure for? - Help please.
Hi, I've decided to create a scheduled task to clean up after windows updates. I've created the task and scheduled it to run every second Saturday of every month (to make sure that it only runs a few days after patch Tuesday). My problem is that I don't understand the "Configure for"...
Performance & Maintenance
Scheduled Task history indicates task completed successfully but....
Hi, New here. I'm using a Scheduled Task to fire a very simple bat file that pulls, compresses and pushes a set of files to a different network directory. The bat file runs fine manually. On a networked desktop I have set up the task to run at about 5am est (waking the machine), as highest...
Performance & Maintenance
Scheduled Task not running
Scheduled Task not running when "run whether user is logged on or not" option is selected? Is this an issue/bug in windows 7?
General Discussion
Event triggered task
I'm trying to evoke a certain script once an event occurs, using the Scheduled Tasks in W7 x64 with event triggering. The script copies a certain file from the USB stick to the HDD. To be precise, the script should run upon specific USB stick is plugged in. So far i only see the...
Hardware & Devices
Scheduled task invisible
Hi, I recently managed to create a musical wake up, using sheduled task and a bat file wich launches mplayerclassic and reads automatically the desired playlist. Problem is, with this sheduled task, I can't stop the player because it doesn't appear anywhere. I verified that I didn't checked...
General Discussion

Our Sites

Site Links

About Us

Find 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 05:51.
Twitter Facebook Google+ Seven Forums iOS App Seven Forums Android App