Question
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. How can you start a task which is triggered by an event?
Answer
In the past, we can use EventMon with custom script to achieve the goal; however, the steps are very complex. Since Vista and Windows Server 2008, Task Scheduler
provides the ability to start a task which is triggered by an event. To do so, you can perform the following steps:
1. OpenTask Scheduler and click Create Task….
2. On theGeneral tab, fill-in the name and configure other settings.
3. On theTriggers tab, click New.
4. SelectOn an event in the Begin the task list box. The following window will be displayed:
![]()
5. On theActions tab, you can create corresponding tasks.
When defining event trigger filters, theBasic option is selected by default. You can configure the eventLog, Source and Event ID based on requirement. If the basic event filter option does not meet the requirement, you can chooseCustom and then New Event Filter to configure advanced event filter settings.
![]()
If the UI of theFilter tab can still not filter the event accurately, you can use theXML tab to provide an event filter in XPath form.
![]()
For example, you have the following event and you only want to trigger the task when the eventTaskName contains value “\CAO updates”.
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
- <System>
<Provider Name="Microsoft-Windows-TaskScheduler" Guid="{de7b24ea-73c8-4a09-985d-5bdadcfa9017}" />
<EventID>201</EventID>
<Version>0</Version>
<Level>4</Level>
<Task>201</Task>
<Opcode>2</Opcode>
<Keywords>0x8000000000000000</Keywords>
<TimeCreated SystemTime="2009-11-26T19:11:10.172Z" />
<EventRecordID>1062725</EventRecordID>
<Correlation ActivityID="{EC84F653-CA0D-4CD0-828E-FDE7D609F86C}" />
<Execution ProcessID="5356" ThreadID="3232" />
<Channel>Microsoft-Windows-TaskScheduler/Operational</Channel>
<Computer>HVDSRV04.vdhvd.nl</Computer>
<Security UserID="S-1-5-21-2744738279-3505563075-3252603895-1260" />
</System>
- <EventData Name="ActionSuccess">
<Data Name="TaskName">\CAO updates</Data>
<Data Name="TaskInstanceId">{EC84F653-CA0D-4CD0-828E-FDE7D609F86C}</Data>
<Data Name="ActionName">D:\AFAS Windows\Kernel\Bin\afascmd.exe</Data>
<Data Name="ResultCode">0</Data>
</EventData>
</Event>
You can specify the following event filter query:
<QueryList>
<Query Id="0" Path="System">
<Select Path="System">*[System[Provider[@Name='Microsoft-Windows-TaskScheduler'] and (Level=4 or Level=0) and (EventID=201)]] and *[EventData[Data[1]='\CAO updates']]</Select>
</Query>
</QueryList>
More Information
EventMon: Stopping a Capture Based on an EventLog Event
http://blogs.technet.com/netmon/archive/2007/02/22/eventmon-stopping-a-capture-based-on-an-eventlog-event.aspx
Applies to
- Windows Server® 2008 operating system
- Windows Server® 2008 R2 operating system