In Windows 11/10 client or Windows Server, using Task Scheduler, you can attach a task for any event in system logs – an administrator can assign a specific script or send e-mail alerts to any Windows event. In this post, we will outline the steps to run a Scheduled Task when an event is triggered in Windows and appears in Event Viewer.
How to run Scheduled Task when an Event is triggered in Windows
System administrators may frequently encounter a situation where you would like to start a task when an event appears. For example, when an event error is logged you may want to start Network Monitor to capture a network trace to analyze the issue further.
Task Scheduler provides the ability to start a task that is triggered by an event. To do so, you can perform the following steps:
- Press the Windows key + R keys to invoke the Run dialog.
- In the Run dialog box, type taskschd.msc and hit Enter to open Task Scheduler.
- Next, click the Action menu and select Create Task.
- On the General tab, fill in the name and configure other settings.
- On the Triggers tab, click New.
- Select On an event in the Begin the task list box.
- On the Actions tab, you can create corresponding tasks.
When defining event trigger filters, the Basic option is selected by default. You can configure the event Log, Source, and Event ID based on the requirement. If the basic event filter option does not meet the requirement, you can choose Custom and then New Event Filter to configure advanced event filter settings.
If the UI of the Filter tab can still not filter the event accurately, you can use the XML tab to provide an event filter in the XPath form.
Related post: How to run Scheduled Task after another Task completes
How do I run a scheduled task immediately in Windows?
Go to the Scheduled Tasks applet in Control Panel, right-click the task you want to start immediately, and select Run from the displayed context menu. To start a scheduled task using the command line, open the command prompt in admin mode and type the following command to change the time to run the task at 9:00 am and hit Enter:
SCHTASKS /CHANGE /TN "FOLDERPATH\TASKNAME" /ST HH:MM Example SCHTASKS /CHANGE /TN "MyTasks\Notepad task" /ST 09:00
How do I run a scheduled task when not logged in?
You can specify that a task should run even if the account under which the task is scheduled to run is not logged on when the task is triggered. To do this, select the radio button labeled Run whether user is logged on or not. If this radio button is selected, tasks will not run interactively.