Re: Improving my script
- From: "Gilliland, Gill" <Gill.Gilliland@xxxxxxxxxxxxxxx>
- Date: Fri, 31 Aug 2007 15:40:09 -0400
The count property works fine in this instance. Thanks!
Here is the updated script example...WATCH WRAPPING!
I plan on creating a control file that contains the server name, service
caption and the service state that I'm monitoring, then setting this as an
async query and loop forever. Then maybe use VBS2EXE and srvany to make the
script a service...I could also configure action flags like cLEAVEALONE,
cSTARTSERVICE, cSTOPSERVICE in the control file to make sure the service is
in a state I want. This could produce a lot of emails if the service decides
to bounce continuously...but I could also configure a retry count...and on,
and on, and on...hehe
Option Explicit
Const cSMTPserver = "<your smtp server>"
Const cSMTPUsername = "your-smtp-userid" 'NOT USED IN THIS SCRIPT
Const cSMTPpassword = "your-smtp-password" 'NOT USED IN THIS SCRIPT
Const cToEmail = "<smtp to address>"
Const cFromEmail = "<smtp from address>"
Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM
Const cdoSendUsingPickup = 1 'Send message using the local SMTP service
pickup directory.
Const cdoSendUsingPort = 2 'Send the message using the network
(SMTP over the network).
Dim sComputer, oWMIService, xServices
sComputer = "."
Set oWMIService = GetObject("winmgmts:\\" & sComputer & "\root\cimv2")
Set xServices = oWMIService.ExecQuery("Select * from Win32_Service Where
Caption='Alerter' AND State='Stopped'")
If xServices.Count<>0 Then SMTPSend "SERVICE MONITOR ALERT", "The Alerter
Service has stopped."
'==========================================================================
'START OF FUNCTIONS AND SUBS
Sub SMTPSend(sSubject, sMessage)
Dim oMsg, oConf, oFields
Set oMsg = CreateObject("CDO.Message")
Set oConf = CreateObject("CDO.Configuration")
Set oFields = oConf.Fields
With oFields
.item("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
cSMTPserver
..Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") =
False
..Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"
) = 60
..Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") =
cdoAnonymous
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") =
cdoSendUsingPort
'.Item("http://schemas.microsoft.com/cdo/configuration/sendusername")
= cSMTPUsername
'.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword")
= cSMTPpassword
.Update
End With
With oMsg
Set .Configuration = oConf
.To = cToEmail
.From = cFromEmail
.Subject = sSubject
.TextBody = sMessage
'use .HTMLBody to send HTML email
'use .AddAttachment to add an attachment
.Fields.Update
.Send
End With
End Sub
'END OF FUNCTIONS AND SUBS
'==========================================================================
On 8/31/07 2:42 PM, in article eXVcl6$6HHA.5404@xxxxxxxxxxxxxxxxxxxx,
"Richard Mueller [MVP]" <rlmueller-nospam@xxxxxxxxxxxxxxxxxxxx> wrote:
In the past I've been able to use the Count property of the collection.
Technically, its a SWbemObjectSet collection, but to me it acts for all the
world like any normal object. We even use a Set statement to instantiate it.
The only thing that works unlike an object is the syntax to enumerate the
collection - we don't specify a method. For example, with group objects we
can use:
For Each objMember in objGroup.Members
The Members method of the group object returns a collection of member
objects. Here we don't use a method:
For Each item In xServices
So, unless there is a default method of the object I cannot find, it is a
collection. Then again, maybe it's a distinction without a difference.
Before posting my previous message I tested to make sure the Count property
worked without error even if the collection is empty.
.
- References:
- Improving my script
- From: Gilliland, Gill
- Re: Improving my script
- From: Paul Randall
- Re: Improving my script
- From: Richard Mueller [MVP]
- Improving my script
- Prev by Date: Re: Improving my script
- Next by Date: vbscript editors
- Previous by thread: Re: Improving my script
- Next by thread: regex backreferance question
- Index(es):
Relevant Pages
|