Send E-Mail When a task in Task Scheduler Fails
You would guess that this would be a really easy task but it turns out this was pretty complicated. Basically, you need to create a scheduled task that gets triggered by an event and do some editing of that task in a notepad. I will just post my exported task here. Feel free to use it / modify it as you want.
<?xml version=”1.0″ encoding=”UTF-16″?>
<Task version=”1.2″ xmlns=”http://schemas.microsoft.com/windows/2004/02/mit/task”>
<RegistrationInfo>
<Date>2012-09-07T09:36:00.5466938</Date>
<Author>Administrator</Author>
</RegistrationInfo>
<Triggers>
<EventTrigger>
<Enabled>true</Enabled>
<Subscription><QueryList><Query Id=”0″ Path=”Microsoft-Windows-TaskScheduler/Operational”><Select Path=”Microsoft-Windows-TaskScheduler/Operational”>*[System[(EventID=201)]] and *[EventData[(Data[@Name=”ResultCode”]!=0)]]</Select></Query></QueryList></Subscription>
<ValueQueries>
<Value name=”custom”>Event/EventData/Data[@Name=’TaskName’]</Value>
<Value name=”eventChannel”>Event/System/Channel</Value>
<Value name=”eventRecordID”>Event/System/EventRecordID</Value>
<Value name=”eventSeverity”>Event/System/Level</Value>
</ValueQueries>
</EventTrigger>
</Triggers>
<Principals>
<Principal id=”Author”>
<UserId>Administrator</UserId>
<LogonType>Password</LogonType>
<RunLevel>LeastPrivilege</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>P3D</ExecutionTimeLimit>
<Priority>7</Priority>
</Settings>
<Actions Context=”Author”>
<SendEmail>
<Server>localhost</Server>
<Subject>Event $(eventRecordID) – $(custom) – $(eventChannel)</Subject>
<To>[email protected]</To>
<From>[email protected]</From>
<Body>Yo!</Body>
<HeaderFields />
<Attachments />
</SendEmail>
</Actions>
</Task>
Just save it as an XML file and import it into the Task Scheduler.