Petri.com forums Home Forums Start Page Forums Frequently Asked Questions FAQ Member List Members List
Go Back   Petri IT Knowledgebase Forums > Windows Scripting > General Scripting
Petri.com is happy to award RicklesP the title of Most Valuable Member !!!
Register Calendar Calendar Search Petri IT Knowledgebase Forums Search Todays Posts Today's Posts Mark Forums Read
Notices

Email when a service falls over

Email when a service falls over

this thread has 5 replies and has been viewed 943 times

Closed Thread
 
Thread Tools Search this Thread Display Modes
  #1  
Old 23rd February 2012, 19:20
jwc1972 jwc1972 is offline
Junior Member
Staying around
 
 Join Date: Jan 2010
  6 month star 12 month star
 Posts: 189
 Reputation: jwc1972 is on a distinguished road (10)
Default Email when a service falls over

Hello

I mod this scripts to check an service on a remore computer, This scripts keeps falling over, Could I somehow get this to email myself?. I have look at the windows server 2008 triggers but did not work eith

Code:
Option explicit
Dim strComputer,strServiceName

strComputer = "192.168.1.16" ' Local Computer
strServiceName = "masage200" ' K3 Service

if isServiceRunning(strComputer,strServiceName) then
  wscript.echo "The '" & strServiceName & "' service is running on '" & strcomputer & "'"
else
  wscript.echo "The '" & strServiceName & "' service is NOT running on '" & strcomputer & "'"
end if

' Function to check if a service is running on a given computer
function isServiceRunning(strComputer,strServiceName)
 Dim objWMIService, strWMIQuery
 strWMIQuery = "Select * from Win32_Service Where Name = '" & strServiceName & "' and state='Running'"
 Set objWMIService = GetObject("winmgmts:" _
  & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
 if objWMIService.ExecQuery(strWMIQuery).Count > 0 then
  isServiceRunning = true
 else
  isServiceRunning = false
 end if
end function

Last edited by Rems; 23rd February 2012 at 22:51..
  #2  
Old 24th February 2012, 13:38
jwc1972 jwc1972 is offline
Junior Member
Staying around
 
 Join Date: Jan 2010
  6 month star 12 month star
 Posts: 189
 Reputation: jwc1972 is on a distinguished road (10)
Default Re: Email when a service falls over

I have founded this

strComputer = "."
strService = "Symantec Antivirus"

Set objEmail = CreateObject("CDO.Message")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Service where DisplayName = '" & Service & "'")
For Each objItem in colItems
If objItem.status <>"OK" or objItem.state <>"Running" then
objEmail.From = "sav@work.com"
objEmail.To = "gorlandini@work.com"
objEmail.Subject = "Antivirus State"
objEmail.Textbody = objItem.DisplayName & " on: " & strComputer _
'" State: " & objItem.State & VbCrLf
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
"smtp.work.com"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
End If
Next

The question what does http://schemas.microsoft.com/cdo/con...tion/sendusing DO?
http://schemas.microsoft.com/cdo/con...ion/smtpserver D0?
  #3  
Old 27th February 2012, 13:18
tehcamel's Avatar
tehcamel tehcamel is offline
Moderator
 
 Join Date: Mar 2009
  6 month star 12 month star
 Location: Melbourne
 Posts: 5,563
  Send a message via Skype™ to tehcamel
 Reputation: tehcamel is a splendid one to beholdtehcamel is a splendid one to beholdtehcamel is a splendid one to beholdtehcamel is a splendid one to beholdtehcamel is a splendid one to beholdtehcamel is a splendid one to behold (656)
Default Re: Email when a service falls over

CDO uses the MAPI library to send an email basically.
simplest form of it is this:

Code:
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Example CDO Message"
objMessage.From = "me@my.com"
objMessage.To = "someone@mydomain.com"
objMessage.TextBody = "This is some sample message text."
objMessage.Send
the other elements you mention allow you to add different options

like this:
Code:
'Not sure what this bit does.
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
 
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.myserver.com"
 
'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
 
objMessage.Configuration.Fields.Update
__________________

Melbourne IT Support


Please do show your appreciation to those who assist you by leaving Rep Point
  #4  
Old 27th February 2012, 13:23
jwc1972 jwc1972 is offline
Junior Member
Staying around
 
 Join Date: Jan 2010
  6 month star 12 month star
 Posts: 189
 Reputation: jwc1972 is on a distinguished road (10)
Default Re: Email when a service falls over

Cheers its working like a dream, These must be to do with the exchange server

'Not sure what this bit does.
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.myserver.com"

'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

objMessage.Configuration.Fields.Update
  #5  
Old 27th February 2012, 13:30
tehcamel's Avatar
tehcamel tehcamel is offline
Moderator
 
 Join Date: Mar 2009
  6 month star 12 month star
 Location: Melbourne
 Posts: 5,563
  Send a message via Skype™ to tehcamel
 Reputation: tehcamel is a splendid one to beholdtehcamel is a splendid one to beholdtehcamel is a splendid one to beholdtehcamel is a splendid one to beholdtehcamel is a splendid one to beholdtehcamel is a splendid one to behold (656)
Default Re: Email when a service falls over

yep.. two parts are to define the SMTP server and the Port.
the other option it seems, it how it sends.

(1) is send using pickup
(2) is send using port
(3) is send using exchange


ref:
http://msdn.microsoft.com/en-us/libr...chg.65%29.aspx
__________________

Melbourne IT Support


Please do show your appreciation to those who assist you by leaving Rep Point
  #6  
Old 29th February 2012, 12:25
jwc1972 jwc1972 is offline
Junior Member
Staying around
 
 Join Date: Jan 2010
  6 month star 12 month star
 Posts: 189
 Reputation: jwc1972 is on a distinguished road (10)
Default Re: Email when a service falls over

Silly Question

I written a vb script to start the service, Silly question Can I give this to a user on their desktop to start the service? she only has domin user access.

option explicit
Dim cimv2, oService, Result , strComputer,strServiceName
strComputer = "192.168.1.9" ' Local Computer
strServiceName = "sage200" ' K3 Service
'Get the WMI administration object
Set cimv2 = GetObject("winmgmts:{impersonationLevel=impersonat e}!\\" & _
strComputer & "\root\cimv2")
'Get the service object
Set oService = cimv2.Get("Win32_Service.Name='" & strServiceName & "'")


'Path = "winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & _
' "\root\cimv2:Win32_Service.Name='" & strServiceName & "'"
'Get the WMI administration object of the service
'Set oService = GetObject(Path)
'Check base properties
If oService.Started Then
' the service is Not started
wscript.echo "The service " & strServiceName & " is all ready running."
Else
' Start the service
oService.StartService
wscript.echo "Start " & strServiceName & " is Now running:"
End If
Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
XP Mode falls asleep RobW Windows 7 1 14th October 2011 03:21
Script to check any service status and send an email with status gorlandini General Scripting 15 23rd March 2009 18:15
SMTP Service periodically stops sending email AH2009 Exchange 2000 / 2003 5 4th December 2008 02:54
The User Profile Service service failed the logon ikroumov Windows Server 2008 / 2008 R2 3 15th May 2008 20:36
Class of Service or Quality of Service? pdania Cisco Routers & Switches How-to 1 11th September 2007 14:37


All times are GMT +3. The time now is 16:55.

Steel Blue 3.5.4 vBulletin Style ©2006 vBEnhanced
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
 

Valid XHTML 1.0!   Valid CSS!

Copyright 2005 Daniel Petri