![]() |
|
|
|||||||
| Petri.co.il is happy to award auglan the title of Most Valuable Member !!! |
| Register | Calendar |
Search |
Today's Posts |
Mark Forums Read |
| Notices |
|
|
Email when a service falls overthis thread has 5 replies and has been viewed 701 times
|
![]() |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||||||
|
||||||||
|
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
|
||||||||
|
||||||||
|
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
|
|||||||||||
|
|||||||||||
|
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
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
__________________
Posting from a BB Playbook - please excuse my typing |
|
#4
|
||||||||
|
||||||||
|
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
|
|||||||||||
|
|||||||||||
|
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
__________________
Posting from a BB Playbook - please excuse my typing |
|
#6
|
||||||||
|
||||||||
|
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 |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
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 |