Solved

Automatically restart a service when an Event is logged.

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
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 tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…

895 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

18 Experts available now in Live!

Get 1:1 Help Now