45

I don't want task scheduler or whatever to wake the computer, but when I open the laptop back up and the machine wakes I'd like that to be the trigger that task scheduler or something uses to run an app.

6 Answers 6

33

You can tick the “Run task as soon as possible after a scheduled start is missed” checkbox on the Settings tab for the task. That's for tasks at least that are scheduled regularly and fail to start due to sleep/hibernate/shutdown.

There doesn't seem to be a trigger "On waking from sleep", but you can probably use the “On Event” trigger. The interesting events seem to be from “Kernel-Power” and “Power-Troubleshooter”. System sleep generates an event from Kernel-Power with event ID 42. Wakeup is an event from Power-Troubleshooter with event ID 1.

8
  • Perhaps I'm not talking about the right even, but I can't seem to get it to work. Basically I'm looking to start the task after putting the notebook computer to sleep (or whatever the actual state happens to be) when I reopen the lid and it comes back on. Usually at this point I have to type in the user password to get access to the system. I've played around with some of the event that seemed relevant to that as well, with no luck.
    – Adam
    Dec 22, 2009 at 17:50
  • "Kernel-Power with event ID 42" worked for me on Windows 7 when activating a bat-file on return from sleep mode
    – user106681
    Nov 24, 2011 at 11:05
  • 2
    This doesn't seem to work when the laptop power cable is unplugged though?
    – anon
    Aug 27, 2014 at 19:29
  • 3
    To clarify, listen to event ID 42 in System log from source Kernel-Power as the sleeping event, and the event ID 1 in System log from source Power-Troubleshooter for computer's resuming (waking). Oct 2, 2016 at 22:25
  • 2
    @ThreaT In Task Scheduler, in the Conditions tab, uncheck "Start the task only if the computer is on AC power"
    – user419144
    Jul 18, 2017 at 8:06
32

The event-based solution suggested by Johannes worked well for me. I wanted a certain text file (my to do list) to open in Notepad every time I un-hibernated my computer (Windows 7). I set up a scheduled task to run with this event as a trigger:

  • Log: System
  • Source:Power-Troubleshooter
  • Event ID: 1

This is working well for me.

0
8

Event 107 when resumed from sleep, and 42 from entering to sleep. I just try event 107 to trigger a program when resume from sleep, and it worked

enter image description here

enter image description here

Schedule tasks

4

There is a simpler method: Triggers > New > On workstation unlock > Any user. When putting the computer to sleep, you're actually (also) locking the machine, and on waking up you will see 'Locked' above the password field, assuming you're using a password.

3
  • a) this is not what the OP asked for b) it might not be desirable to run it on that event -- depends on the use case
    – elonderin
    Feb 25, 2020 at 16:27
  • @elonderin — The OP is asking how he can trigger the Task Scheduler when the computer is waking up from sleep/hibernate. I think I gave him a method how to do that. Apr 26, 2020 at 13:29
  • but your solution would also run when you just lock /unlock your account w/o any sleep state involved but the OP was asking for when coming out of sleep. Hence, depending on the use case this might be valid or not.
    – elonderin
    Apr 26, 2020 at 21:17
2

Below is an AutoHotkey solution based on a similar question

Save the (one line) script below with file ending .ahk:

Send {Volume_Down 100} ; Turns the volume DOWN 100 intervals

To run it on login or when the computer wakes, there is a AutoHotkey script that attempts to solve this here, or you can run the script using Task Scheduler.

More information can be found here (control volume) and here (for using AutoHotkey).

3
  • The question was about doing anything when the computer resumes from sleep or hibernation. The question was not about how to turn the volume down.
    – jous
    Jan 18, 2022 at 12:24
  • For details of achieving this: autohotkey.com/board/topic/…
    – Stenemo
    Jan 19, 2022 at 18:58
  • +1 because it works. However; its a perfect example on how to solve a problem, which has a simple solution with the event trigger, in the most complex way possible. however, you should probably change the ahk syntax to inserting some text into a text file, to please the OP question.
    – Christian
    Jan 5, 2023 at 15:02
0

I use the task scheduler with AutoHotKey script to relaunch TT RGB Plus from sleep, because the program doesn't always work from sleep. Kind of ridiculous I have to do it this way but it works.

Sleep, 3000
Process, Close, TT RGB Plus.exe
Sleep, 2000
Run C:\Program Files\Tt\TT RGB Plus\TTRGBPlusGUI.exe
Sleep, 15000
Process, Close, TT RGB Plus.exe

My computer never goes to a lock screen so I use the event mentioned above in task scheduler and it works.

Log: System
Source:Power-Troubleshooter
Event ID: 1

The you have it "start a program" and launch the script.

1
  • The first word of the last line should be "Then", not "The". Please edit and fix. Jul 24, 2022 at 7:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .