Solved

Schedule task on an event

Posted on 2014-09-29
3
608 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
New Windows 7 Installations take days for Windows-Updates to show up and install. This can easily be fixed. I have finally decided to write an article because this seems to get asked several times a day lately. This Article and the Links apply to…
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now