?
Solved

Schedule task on an event

Posted on 2014-09-29
3
Medium Priority
?
870 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 2000 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
For anyone that has accidentally used newSID with Server 2008 R2 (like I did) and hasn't been able to get the server running again because you were unlucky (as I was) and had no backups - I was able to get things working by doing a Registry Hive rec…
This tutorial will give a short introduction and overview of Backup Exec 2012 and how to navigate and perform basic functions. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as conne…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Suggested Courses

764 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