windows1711 Posted August 2, 2014 Report Share Posted August 2, 2014 Hi, I need to monitor a service in windows server and when it stops need to send an email. I got the batch file script strComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colMonitoredProcesses = objWMIService. _ ExecNotificationQuery("Select * From __InstanceModificationEvent " _ & " Within 1 where TargetInstance ISA 'Win32_Service'") Do While True Set objLatestProcess = colMonitoredProcesses.NextEvent If LCase(objLatestProcess.TargetInstance.Name) = "Tomcat6" Then 'Name of service quoted; do not use display name If objLatestProcess.TargetInstance.State = "Stop pending" Then Call SendMail End if If objLatestProcess.TargetInstance.State = "Stopped" Then Call SendMail End if End ifLoop Sub SendMail()Set cdo = CreateObject("CDO.Message")With cdo.Subject = "Service Down" 'email subject line quoted.From = "" 'your email address quoted.To = "" 'recipient email address quoted.TextBody = "Tomcat Service Down, please start the service" 'email body text quoted.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "" 'your ISP SMTP server address.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 .Configuration.Fields.Update .SendEnd WithSet cdo = Nothing End Sub When i ran this batch file it throwed the below error, could you please help me to resolve this.'strComputer' is not recognized as an internal or external command,operable program or batch file. d:\>Set objWMIService = GetObject("winmgmts:" _& was unexpected at this time. d:\> & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Thanks, Quote Link to comment Share on other sites More sharing options...
ɹəuəllıʍ ʇɐb Posted August 3, 2014 Report Share Posted August 3, 2014 Welcome to the Windows Forum! What language is that script in? I do not recognize the language. Anyway, the first error...You use 'Set' to assign values throughout the script, but not in the case of strComputer = "." As for the next error, what is that underscore at the end of the line - some kind of continuation mark? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.