Solved

Automatically restart a service when an Event is logged.

Posted on 2014-01-27
3
409 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
  • 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
A procedure for exporting installed hotfix details of remote computers using powershell
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…

707 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

17 Experts available now in Live!

Get 1:1 Help Now