Solved

Automatically restart a service when an Event is logged.

Posted on 2014-01-27
3
414 Views
Last Modified: 2014-01-27
Hi Team,

I need to find a workaround to an issue I've been having for a while. My goal is to create a BAT file that restarts a service, I have already created the file and it works. Now my next step is for this BAT file to execute automatically every time an error event is logged in the applications logs. I have the event ID number but I don't how to check for this.

Thank you
0
Comment
Question by:exTechnology
[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 1

Accepted Solution

by:
Thomas Dark earned 300 total points
ID: 39811976
Hi exTechnology,

In Server 2008, you can use a scheduled task to accomplish this. "When a specific event is logged" in the schedule options. For Server 2003, this may be more awkward. You may need a WMI call to check for the event.

I'll keep looking to find a simpler option.

Regards,
Tom
0
 
LVL 1

Expert Comment

by:Thomas Dark
ID: 39811991
Hi exTechnology,

I've found that "EventTriggers.exe" does what I believe you're after. See the link below for full details/syntax.

http://technet.microsoft.com/en-us/library/bb490901.aspx

Kind Regards,
Tom
0
 
LVL 3

Expert Comment

by:SandyWalve
ID: 39812055
You can take help of LogParser.exe

Query your Events (System/APplicaiton for specific Event ID) Which will throw result in CSV File. There will be a script that is executed to check whether file is generated or not. If no events no file is generated. If found event, file will be generated and it will trigger the service restart.

Download Log Parser
http://www.orcsweb.com/blog/desiree/how-to-use-log-parser-to-query-event-log-data/

Save below in a Batch file with name LogScan.bat

cd\
C:
cd Monitoring\LogParser

LogParser.exe -i:EVT -o:CSV "SELECT ComputerName,EventLog,EventID,SourceName,Strings,TimeGenerated,Message INTO C:\Monitoring\LogParser\Error_Events.csv FROM \\<Server IP/Name>\Application where EventID=<EventID> and TimeGenerated >= TO_LOCALTIME(SUB( SYSTEM_TIMESTAMP(), TIMESTAMP( '05', 'mm' ) ) )"

cscript RestartService.vbs

Save below as RestartService.vbs

Dim fso,msgstr

Set fso = CreateObject("Scripting.FileSystemObject")
Set shell = CreateObject("Wscript.Shell")


if (fso.FileExists("C:\Monitoring\LogParser\Error_Events.csv")) then       
       shell.Run "C:\Monitoring\ServiceRestart.bat", 1, True
end if

set fso=nothing
set shell=nothing

Save below as ServiceRestart.bat

net stop <ServiceName>
net start <ServiceName>
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Background Information Recently I have fixed file server permission issues for one of my client. The client has 1800 users and one Windows Server 2008 R2 domain joined file server with 12 TB of data, 250+ shared folders and the folder structure i…
Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
This tutorial will walk an individual through locating and launching the BEUtility application to properly change the service account username and\or password in situation where it may be necessary or where the password has been inadvertently change…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

696 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