?
Solved

Automatically restart a service when an Event is logged.

Posted on 2014-01-27
3
Medium Priority
?
432 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 1200 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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

Learn about cloud computing and its benefits for small business owners.
A safe way to clean winsxs folder from your windows server 2008 R2 editions
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…
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…
Suggested Courses

850 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