Solved

Schedule task on an event

Posted on 2014-09-29
3
722 Views
Last Modified: 2014-10-05
I want to run a batch file in task scheduler on an event.

This is the event in windows events viewer in xml eventdata

 <System>
  <Provider Name="User32" Guid="{b0aa8734-56f7-41cc-b2f4-de228e98b946}" EventSourceName="User32" /> 
  <EventID Qualifiers="32768">1074</EventID> 
  <Version>0</Version> 
  <Level>4</Level> 
  <Task>0</Task> 
  <Opcode>0</Opcode> 
  <Keywords>0x8080000000000000</Keywords> 
  <TimeCreated SystemTime="2014-09-25T23:21:17.892345300Z" /> 
  <EventRecordID>10427</EventRecordID> 
  <Correlation /> 
  <Execution ProcessID="568" ThreadID="1816" /> 
  <Channel>System</Channel> 
  <Computer>SV1.nortool.local</Computer> 
  <Security UserID="S-1-5-21-3322805290-1362380017-3951582809-1106" /> 
  </System>
- <EventData>
  <Data Name="param1">C:\Windows\Explorer.EXE (SV1)</Data> 
  <Data Name="param2">SV1</Data> 
  <Data Name="param3">Other (Unplanned)</Data> 
  <Data Name="param4">0x5000000</Data> 
  <Data Name="param5">power off</Data> 
  <Data Name="param6" /> 
  <Data Name="param7">NORTOOL\NTAdmin</Data> 
  </EventData>
  </Event>

Open in new window


I want to run the batch file for this event data:
 <EventID Qualifiers="32768">1074</EventID> 
<Data Name="param5">power off</Data> 

Open in new window


When in the task schedule I created the following in the "Edit Event Filter" screen and need to know how to include <Data Name="param5">power off</Data>

<QueryList>
  <Query Id="0" Path="System">
    <Select Path="System">*[System[(EventID=1079)]]</Select>
  </Query>
</QueryList>

Open in new window


This is for a Windows 2012 R2 server
0
Comment
Question by:Gerhardpet
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 40354171
This should do the trick:
<QueryList>
  <Query Id="0" Path="System">
    <Select Path="System">*[System[(EventID=1074)]][EventData[(Data[@Name='param5']='power off')]]</Select>
  </Query>
</QueryList>

Open in new window

which is equivalent to:
<QueryList>
  <Query Id="0" Path="System">
    <Select Path="System">*[System[(EventID=1074)] and EventData[(Data[@Name='param5']='power off')]]</Select>
  </Query>
</QueryList>

Open in new window

So the first one (which for no particular reason is my personal preference) uses 2 consecutive "[ ... ]" selectors which are both applied to * (which always matches the Event node) where the second one uses "... and ..." to do the same.

Here are some more examples: http://msdn.microsoft.com/en-us/library/aa385231(VS.85).aspx

In general, it should be possible to use any XPath query selector: http://msdn.microsoft.com/en-us/library/ms256086(v=vs.110).aspx
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 40354176
tested in Event Viewer filter:
captureThe events where 'param5' is 'shutdown' or 'restart' are not shown anymore, so seems to work ok ;-)
0
 
LVL 1

Author Closing Comment

by:Gerhardpet
ID: 40362102
That did the trick. Thank you Robert!!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Understanding the various editions available is vital when you decide to purchase Windows Server 2012. You need to have a basic understanding of the features and limitations in each edition in order to make a well-informed decision that best suits y…
The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question