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

idecz

New member
Local time
12:18 PM
Messages
6
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 My Computer

At a glance

Windows 7 Ultimate x64i5 2500K8.00 GB Dual-Channel DDR3 @ 800MHzASUS DirectCUII Radeon HD6950
OS
Windows 7 Ultimate x64
CPU
i5 2500K
Motherboard
ASUS P8Z68 DELUXE
Memory
8.00 GB Dual-Channel DDR3 @ 800MHz
Graphics Card(s)
ASUS DirectCUII Radeon HD6950
Sound Card
Creative X-Fi Fatal1ty
Monitor(s) Displays
DELL 2007WFP, Acer v19w
PSU
1000W
Does your task need to run before going to Sleep, or would it be ok to run it on Wakeup?
 

My Computer My Computer

At a glance

Multi-Boot W7_Pro_x64 W8.1_Pro_x64 W10_Pro_x6...AMD Athlon II x4 6206GB GSkill DDR2 800AMD 4670 GPU + AMD 4200 IGP
Computer type
PC/Desktop
Computer Manufacturer/Model Number
home built
OS
Multi-Boot W7_Pro_x64 W8.1_Pro_x64 W10_Pro_x64 +Linux_VMs +Chromium_VM
CPU
AMD Athlon II x4 620
Motherboard
Gigabyte GA-MA785G-UD3H
Memory
6GB GSkill DDR2 800
Graphics Card(s)
AMD 4670 GPU + AMD 4200 IGP
Sound Card
on board Realtek ALC889A
Monitor(s) Displays
RCA 40" LCD TV, Insignia 32" LCD TV, HP 15" LCD monitor
Screen Resolution
1680 x 1050
Hard Drives
OCZ Vertex 3 120GB,
Samsung F3 1TB (3),
Several others - WD, Seagate, Hitachi, ...
PSU
Corsair 500 W
Case
Rosewill mid tower
Cooling
CM 90mm rifle
Keyboard
Gyration wireless, Logitech wireless, Dell USB wired
Mouse
Gyration wireless, Logitech wireless, V7 USB wired
Internet Speed
Spectrum - 100Mbps D / 10Mbps U
Antivirus
Avast, MBAM3, EMET, WinPatrol
Browser
Pale Moon, Firefox, IE
Other Info
2 multi-boot PC's
Mainly HTPC/Office/Gen purpose (no gaming).
Trendnet USB KVM.
LG DVD burner/Blue Ray Player.
Tray system for removable SATA backup drives.

Not currently OCd, under-volted.
I use Hybrid sleep, rarely re-boot or shutdown.

Hauppauge HD-PVR, Avermedia PCIe TV Tuner, Hauppauge PCI TV Tuner.
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:

My Computer My Computer

At a glance

Windows 7 Ultimate x64i5 2500K8.00 GB Dual-Channel DDR3 @ 800MHzASUS DirectCUII Radeon HD6950
OS
Windows 7 Ultimate x64
CPU
i5 2500K
Motherboard
ASUS P8Z68 DELUXE
Memory
8.00 GB Dual-Channel DDR3 @ 800MHz
Graphics Card(s)
ASUS DirectCUII Radeon HD6950
Sound Card
Creative X-Fi Fatal1ty
Monitor(s) Displays
DELL 2007WFP, Acer v19w
PSU
1000W
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 My Computer

At a glance

Windows 7 Ultimate x64i5 2500K8.00 GB Dual-Channel DDR3 @ 800MHzASUS DirectCUII Radeon HD6950
OS
Windows 7 Ultimate x64
CPU
i5 2500K
Motherboard
ASUS P8Z68 DELUXE
Memory
8.00 GB Dual-Channel DDR3 @ 800MHz
Graphics Card(s)
ASUS DirectCUII Radeon HD6950
Sound Card
Creative X-Fi Fatal1ty
Monitor(s) Displays
DELL 2007WFP, Acer v19w
PSU
1000W
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 My Computer

At a glance

Multi-Boot W7_Pro_x64 W8.1_Pro_x64 W10_Pro_x6...AMD Athlon II x4 6206GB GSkill DDR2 800AMD 4670 GPU + AMD 4200 IGP
Computer type
PC/Desktop
Computer Manufacturer/Model Number
home built
OS
Multi-Boot W7_Pro_x64 W8.1_Pro_x64 W10_Pro_x64 +Linux_VMs +Chromium_VM
CPU
AMD Athlon II x4 620
Motherboard
Gigabyte GA-MA785G-UD3H
Memory
6GB GSkill DDR2 800
Graphics Card(s)
AMD 4670 GPU + AMD 4200 IGP
Sound Card
on board Realtek ALC889A
Monitor(s) Displays
RCA 40" LCD TV, Insignia 32" LCD TV, HP 15" LCD monitor
Screen Resolution
1680 x 1050
Hard Drives
OCZ Vertex 3 120GB,
Samsung F3 1TB (3),
Several others - WD, Seagate, Hitachi, ...
PSU
Corsair 500 W
Case
Rosewill mid tower
Cooling
CM 90mm rifle
Keyboard
Gyration wireless, Logitech wireless, Dell USB wired
Mouse
Gyration wireless, Logitech wireless, V7 USB wired
Internet Speed
Spectrum - 100Mbps D / 10Mbps U
Antivirus
Avast, MBAM3, EMET, WinPatrol
Browser
Pale Moon, Firefox, IE
Other Info
2 multi-boot PC's
Mainly HTPC/Office/Gen purpose (no gaming).
Trendnet USB KVM.
LG DVD burner/Blue Ray Player.
Tray system for removable SATA backup drives.

Not currently OCd, under-volted.
I use Hybrid sleep, rarely re-boot or shutdown.

Hauppauge HD-PVR, Avermedia PCIe TV Tuner, Hauppauge PCI TV Tuner.
Back
Top