Solved

Automatically restart a service when an Event is logged.

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…
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…

856 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