I have this test script:

Option Explicit

Dim sComputer, oWMIService, xServices, item

sComputer = "."
Set oWMIService = GetObject("winmgmts:\\" & sComputer & "\root\cimv2")
Set xServices = oWMIService.ExecQuery("Select * from Win32_Service Where
Caption='Alerter' AND State='Stopped'")

For Each item In xServices
If item.Caption = "Alerter" Then
WScript.Echo "Doing some action because Alerter is stopped."
End If
Next


Is there a way to determine if xServices is empty or not without using a For
Each loop? For instance, if the Alerter service is started, the example
script above should not have any items in the xServices collection. (btw, is
xServices a collection or an object?)


Thanks,

Gill

Re: Improving my script by Richard

Richard
Fri Aug 31 11:15:25 PDT 2007

Gill wrote:

>I have this test script:
>
> Option Explicit
>
> Dim sComputer, oWMIService, xServices, item
>
> sComputer = "."
> Set oWMIService = GetObject("winmgmts:\\" & sComputer & "\root\cimv2")
> Set xServices = oWMIService.ExecQuery("Select * from Win32_Service Where
> Caption='Alerter' AND State='Stopped'")
>
> For Each item In xServices
> If item.Caption = "Alerter" Then
> WScript.Echo "Doing some action because Alerter is stopped."
> End If
> Next
>
>
> Is there a way to determine if xServices is empty or not without using a
> For
> Each loop? For instance, if the Alerter service is started, the example
> script above should not have any items in the xServices collection. (btw,
> is
> xServices a collection or an object?)

The ExecQuery method returns a SWbemObjectSet collection. It has properties
like Count. For example:

If (xServices.Count = 0) then
' xServices is empty.
Else
' xServices has one or more objects.
End If

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--



Re: Improving my script by Paul

Paul
Fri Aug 31 11:20:31 PDT 2007

Hi, Gill
I'm glad I'm not the only one having a problem with the collection/object
thing. Michael Harris tried to explain it to me about 5 years ago, but my
brain doesn't want to understand, I guess. A collection is an object.
Normally this collection object has a count or length property but I have a
hard time remembering which objects have the count property and which use
length in a similar manner. I guess that is why we like editors that
display the valid property names while we are typing our code. Anyhow, some
collections have neither a count nor length property.

I've found only one way to obtain that count: loop through the collection
and count the contents with your code. Then I run into the problem that I
can't loop through that same collection again -- it can only be 'For Each'ed
once. You have to create the collection again if you want to loop through
it again. If creating the collection a second time takes too many
resources, you might consider adding a line or two to your 'For Each' loop
to store the items in a dictionary, which will give you quick, repeatable,
sequential and hashed access to the items in the collection and also keeps a
count.

I hope someone can clarify this better than I have.

-Paul Randall

"Gilliland, Gill" <Gill.Gilliland@UnitedWater.com> wrote in message
news:C2FDCD50.538D%Gill.Gilliland@UnitedWater.com...
>I have this test script:
>
> Option Explicit
>
> Dim sComputer, oWMIService, xServices, item
>
> sComputer = "."
> Set oWMIService = GetObject("winmgmts:\\" & sComputer & "\root\cimv2")
> Set xServices = oWMIService.ExecQuery("Select * from Win32_Service Where
> Caption='Alerter' AND State='Stopped'")
>
> For Each item In xServices
> If item.Caption = "Alerter" Then
> WScript.Echo "Doing some action because Alerter is stopped."
> End If
> Next
>
>
> Is there a way to determine if xServices is empty or not without using a
> For
> Each loop? For instance, if the Alerter service is started, the example
> script above should not have any items in the xServices collection. (btw,
> is
> xServices a collection or an object?)
>
>
> Thanks,
>
> Gill
>



Re: Improving my script by Richard

Richard
Fri Aug 31 11:42:00 PDT 2007

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.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--

"Paul Randall" <paulr901@cableone.net> wrote in message
news:uPIBHu$6HHA.2476@TK2MSFTNGP05.phx.gbl...
> Hi, Gill
> I'm glad I'm not the only one having a problem with the collection/object
> thing. Michael Harris tried to explain it to me about 5 years ago, but my
> brain doesn't want to understand, I guess. A collection is an object.
> Normally this collection object has a count or length property but I have
> a hard time remembering which objects have the count property and which
> use length in a similar manner. I guess that is why we like editors that
> display the valid property names while we are typing our code. Anyhow,
> some collections have neither a count nor length property.
>
> I've found only one way to obtain that count: loop through the collection
> and count the contents with your code. Then I run into the problem that I
> can't loop through that same collection again -- it can only be 'For
> Each'ed once. You have to create the collection again if you want to loop
> through it again. If creating the collection a second time takes too many
> resources, you might consider adding a line or two to your 'For Each' loop
> to store the items in a dictionary, which will give you quick, repeatable,
> sequential and hashed access to the items in the collection and also keeps
> a count.
>
> I hope someone can clarify this better than I have.
>
> -Paul Randall
>
> "Gilliland, Gill" <Gill.Gilliland@UnitedWater.com> wrote in message
> news:C2FDCD50.538D%Gill.Gilliland@UnitedWater.com...
>>I have this test script:
>>
>> Option Explicit
>>
>> Dim sComputer, oWMIService, xServices, item
>>
>> sComputer = "."
>> Set oWMIService = GetObject("winmgmts:\\" & sComputer & "\root\cimv2")
>> Set xServices = oWMIService.ExecQuery("Select * from Win32_Service Where
>> Caption='Alerter' AND State='Stopped'")
>>
>> For Each item In xServices
>> If item.Caption = "Alerter" Then
>> WScript.Echo "Doing some action because Alerter is stopped."
>> End If
>> Next
>>
>>
>> Is there a way to determine if xServices is empty or not without using a
>> For
>> Each loop? For instance, if the Alerter service is started, the example
>> script above should not have any items in the xServices collection. (btw,
>> is
>> xServices a collection or an object?)
>>
>>
>> Thanks,
>>
>> Gill
>>
>
>



Re: Improving my script by Paul

Paul
Fri Aug 31 12:39:37 PDT 2007

Thanks, Richard.

My problem occurred about 5 years ago on a W98SE system. I think it was a
WMI-related collection but I'm not sure. If groups.google worked reliably
when specifying author, I'm sure I could find it but this feature has become
almost useless lately.

-Paul Randall

"Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote in
message news:eXVcl6$6HHA.5404@TK2MSFTNGP02.phx.gbl...
> 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.
>
> --
> Richard Mueller
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
> --
>
> "Paul Randall" <paulr901@cableone.net> wrote in message
> news:uPIBHu$6HHA.2476@TK2MSFTNGP05.phx.gbl...
>> Hi, Gill
>> I'm glad I'm not the only one having a problem with the collection/object
>> thing. Michael Harris tried to explain it to me about 5 years ago, but
>> my brain doesn't want to understand, I guess. A collection is an object.
>> Normally this collection object has a count or length property but I have
>> a hard time remembering which objects have the count property and which
>> use length in a similar manner. I guess that is why we like editors that
>> display the valid property names while we are typing our code. Anyhow,
>> some collections have neither a count nor length property.
>>
>> I've found only one way to obtain that count: loop through the collection
>> and count the contents with your code. Then I run into the problem that
>> I can't loop through that same collection again -- it can only be 'For
>> Each'ed once. You have to create the collection again if you want to
>> loop through it again. If creating the collection a second time takes
>> too many resources, you might consider adding a line or two to your 'For
>> Each' loop to store the items in a dictionary, which will give you quick,
>> repeatable, sequential and hashed access to the items in the collection
>> and also keeps a count.
>>
>> I hope someone can clarify this better than I have.
>>
>> -Paul Randall
>>
>> "Gilliland, Gill" <Gill.Gilliland@UnitedWater.com> wrote in message
>> news:C2FDCD50.538D%Gill.Gilliland@UnitedWater.com...
>>>I have this test script:
>>>
>>> Option Explicit
>>>
>>> Dim sComputer, oWMIService, xServices, item
>>>
>>> sComputer = "."
>>> Set oWMIService = GetObject("winmgmts:\\" & sComputer & "\root\cimv2")
>>> Set xServices = oWMIService.ExecQuery("Select * from Win32_Service Where
>>> Caption='Alerter' AND State='Stopped'")
>>>
>>> For Each item In xServices
>>> If item.Caption = "Alerter" Then
>>> WScript.Echo "Doing some action because Alerter is stopped."
>>> End If
>>> Next
>>>
>>>
>>> Is there a way to determine if xServices is empty or not without using a
>>> For
>>> Each loop? For instance, if the Alerter service is started, the example
>>> script above should not have any items in the xServices collection.
>>> (btw, is
>>> xServices a collection or an object?)
>>>
>>>
>>> Thanks,
>>>
>>> Gill
>>>
>>
>>
>
>



Re: Improving my script by Gilliland,

Gilliland,
Fri Aug 31 12:40:09 PDT 2007

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@TK2MSFTNGP02.phx.gbl,
"Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> 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.


Re: Improving my script by Richard

Richard
Fri Aug 31 13:52:20 PDT 2007

I've noticed that google no longer finds older threads, whether I search by
author or keywords. Things I know were discussed a year ago seem to be lost.
Not good.

Richard Mueller

"Paul Randall" <paulr901@cableone.net> wrote in message
news:ubHuTaA7HHA.1900@TK2MSFTNGP02.phx.gbl...
> Thanks, Richard.
>
> My problem occurred about 5 years ago on a W98SE system. I think it was a
> WMI-related collection but I'm not sure. If groups.google worked reliably
> when specifying author, I'm sure I could find it but this feature has
> become almost useless lately.
>
> -Paul Randall
>
> "Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote in
> message news:eXVcl6$6HHA.5404@TK2MSFTNGP02.phx.gbl...
>> 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.
>>
>> --
>> Richard Mueller
>> Microsoft MVP Scripting and ADSI
>> Hilltop Lab - http://www.rlmueller.net
>> --
>>
>> "Paul Randall" <paulr901@cableone.net> wrote in message
>> news:uPIBHu$6HHA.2476@TK2MSFTNGP05.phx.gbl...
>>> Hi, Gill
>>> I'm glad I'm not the only one having a problem with the
>>> collection/object thing. Michael Harris tried to explain it to me about
>>> 5 years ago, but my brain doesn't want to understand, I guess. A
>>> collection is an object. Normally this collection object has a count or
>>> length property but I have a hard time remembering which objects have
>>> the count property and which use length in a similar manner. I guess
>>> that is why we like editors that display the valid property names while
>>> we are typing our code. Anyhow, some collections have neither a count
>>> nor length property.
>>>
>>> I've found only one way to obtain that count: loop through the
>>> collection and count the contents with your code. Then I run into the
>>> problem that I can't loop through that same collection again -- it can
>>> only be 'For Each'ed once. You have to create the collection again if
>>> you want to loop through it again. If creating the collection a second
>>> time takes too many resources, you might consider adding a line or two
>>> to your 'For Each' loop to store the items in a dictionary, which will
>>> give you quick, repeatable, sequential and hashed access to the items in
>>> the collection and also keeps a count.
>>>
>>> I hope someone can clarify this better than I have.
>>>
>>> -Paul Randall
>>>
>>> "Gilliland, Gill" <Gill.Gilliland@UnitedWater.com> wrote in message
>>> news:C2FDCD50.538D%Gill.Gilliland@UnitedWater.com...
>>>>I have this test script:
>>>>
>>>> Option Explicit
>>>>
>>>> Dim sComputer, oWMIService, xServices, item
>>>>
>>>> sComputer = "."
>>>> Set oWMIService = GetObject("winmgmts:\\" & sComputer & "\root\cimv2")
>>>> Set xServices = oWMIService.ExecQuery("Select * from Win32_Service
>>>> Where
>>>> Caption='Alerter' AND State='Stopped'")
>>>>
>>>> For Each item In xServices
>>>> If item.Caption = "Alerter" Then
>>>> WScript.Echo "Doing some action because Alerter is stopped."
>>>> End If
>>>> Next
>>>>
>>>>
>>>> Is there a way to determine if xServices is empty or not without using
>>>> a For
>>>> Each loop? For instance, if the Alerter service is started, the example
>>>> script above should not have any items in the xServices collection.
>>>> (btw, is
>>>> xServices a collection or an object?)
>>>>
>>>>
>>>> Thanks,
>>>>
>>>> Gill
>>>>
>>>
>>>
>>
>>
>
>



Re: Improving my script by Paul

Paul
Fri Aug 31 16:12:02 PDT 2007

Your response made me try Googling again.
groups.google.com/advanced_search?q=&
with all the words: collection
with the exact phrase: paul randall
start date 1 Jan 1995
end date 31 Dec 2005

The first item is exactly what I was looking for:
Defective WMI collection. Turns out it wasn't Michael Harris that tried to
explain it to me.

Ivan Brugiolo [MS]
It dipends on the style of the enumeration. A forward only enumeration can
be used only once in a meaningful way. The "Collections" are not a concept
in WinMgmt. You can obtain an enumerator from a SWbemObjectSet, that might
behave as a "Collection".

Maybe we are talking apples and oranges or enumerations and collections.

Thanks,
-Paul Randall

"Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote in
message news:u4iCmDB7HHA.1212@TK2MSFTNGP05.phx.gbl...
> I've noticed that google no longer finds older threads, whether I search
> by author or keywords. Things I know were discussed a year ago seem to be
> lost. Not good.
>
> Richard Mueller
>
> "Paul Randall" <paulr901@cableone.net> wrote in message
> news:ubHuTaA7HHA.1900@TK2MSFTNGP02.phx.gbl...
>> Thanks, Richard.
>>
>> My problem occurred about 5 years ago on a W98SE system. I think it was
>> a WMI-related collection but I'm not sure. If groups.google worked
>> reliably when specifying author, I'm sure I could find it but this
>> feature has become almost useless lately.
>>
>> -Paul Randall
>>
>> "Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote in
>> message news:eXVcl6$6HHA.5404@TK2MSFTNGP02.phx.gbl...
>>> 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.
>>>
>>> --
>>> Richard Mueller
>>> Microsoft MVP Scripting and ADSI
>>> Hilltop Lab - http://www.rlmueller.net
>>> --
>>>
>>> "Paul Randall" <paulr901@cableone.net> wrote in message
>>> news:uPIBHu$6HHA.2476@TK2MSFTNGP05.phx.gbl...
>>>> Hi, Gill
>>>> I'm glad I'm not the only one having a problem with the
>>>> collection/object thing. Michael Harris tried to explain it to me
>>>> about 5 years ago, but my brain doesn't want to understand, I guess. A
>>>> collection is an object. Normally this collection object has a count or
>>>> length property but I have a hard time remembering which objects have
>>>> the count property and which use length in a similar manner. I guess
>>>> that is why we like editors that display the valid property names while
>>>> we are typing our code. Anyhow, some collections have neither a count
>>>> nor length property.
>>>>
>>>> I've found only one way to obtain that count: loop through the
>>>> collection and count the contents with your code. Then I run into the
>>>> problem that I can't loop through that same collection again -- it can
>>>> only be 'For Each'ed once. You have to create the collection again if
>>>> you want to loop through it again. If creating the collection a second
>>>> time takes too many resources, you might consider adding a line or two
>>>> to your 'For Each' loop to store the items in a dictionary, which will
>>>> give you quick, repeatable, sequential and hashed access to the items
>>>> in the collection and also keeps a count.
>>>>
>>>> I hope someone can clarify this better than I have.
>>>>
>>>> -Paul Randall
>>>>
>>>> "Gilliland, Gill" <Gill.Gilliland@UnitedWater.com> wrote in message
>>>> news:C2FDCD50.538D%Gill.Gilliland@UnitedWater.com...
>>>>>I have this test script:
>>>>>
>>>>> Option Explicit
>>>>>
>>>>> Dim sComputer, oWMIService, xServices, item
>>>>>
>>>>> sComputer = "."
>>>>> Set oWMIService = GetObject("winmgmts:\\" & sComputer & "\root\cimv2")
>>>>> Set xServices = oWMIService.ExecQuery("Select * from Win32_Service
>>>>> Where
>>>>> Caption='Alerter' AND State='Stopped'")
>>>>>
>>>>> For Each item In xServices
>>>>> If item.Caption = "Alerter" Then
>>>>> WScript.Echo "Doing some action because Alerter is stopped."
>>>>> End If
>>>>> Next
>>>>>
>>>>>
>>>>> Is there a way to determine if xServices is empty or not without using
>>>>> a For
>>>>> Each loop? For instance, if the Alerter service is started, the
>>>>> example
>>>>> script above should not have any items in the xServices collection.
>>>>> (btw, is
>>>>> xServices a collection or an object?)
>>>>>
>>>>>
>>>>> Thanks,
>>>>>
>>>>> Gill
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>



Re: Improving my script by urkec

urkec
Sat Sep 01 01:36:00 PDT 2007

"Paul Randall" wrote:

> Your response made me try Googling again.
> groups.google.com/advanced_search?q=&
> with all the words: collection
> with the exact phrase: paul randall
> start date 1 Jan 1995
> end date 31 Dec 2005
>
> The first item is exactly what I was looking for:
> Defective WMI collection. Turns out it wasn't Michael Harris that tried to
> explain it to me.
>
> Ivan Brugiolo [MS]
> It dipends on the style of the enumeration. A forward only enumeration can
> be used only once in a meaningful way. The "Collections" are not a concept
> in WinMgmt. You can obtain an enumerator from a SWbemObjectSet, that might
> behave as a "Collection".
>
> Maybe we are talking apples and oranges or enumerations and collections.
>

So, if I understand this, I can use SwbemObjectSet.Count and then For Each,
but when SwbemObjectSet is returned with forward only flag, SwbemObjectSet
doesn't have Count property and I get that error?

--
urkec

Re: Improving my script by Paul

Paul
Sat Sep 01 02:14:30 PDT 2007

"urkec" <urkec@discussions.microsoft.com> wrote in message
news:F5EA2B11-A887-413A-BBEF-9647E53018A7@microsoft.com...
> "Paul Randall" wrote:
>
>> Your response made me try Googling again.
>> groups.google.com/advanced_search?q=&
>> with all the words: collection
>> with the exact phrase: paul randall
>> start date 1 Jan 1995
>> end date 31 Dec 2005
>>
>> The first item is exactly what I was looking for:
>> Defective WMI collection. Turns out it wasn't Michael Harris that tried
>> to
>> explain it to me.
>>
>> Ivan Brugiolo [MS]
>> It dipends on the style of the enumeration. A forward only enumeration
>> can
>> be used only once in a meaningful way. The "Collections" are not a
>> concept
>> in WinMgmt. You can obtain an enumerator from a SWbemObjectSet, that
>> might
>> behave as a "Collection".
>>
>> Maybe we are talking apples and oranges or enumerations and collections.
>>
>
> So, if I understand this, I can use SwbemObjectSet.Count and then For
> Each,
> but when SwbemObjectSet is returned with forward only flag, SwbemObjectSet
> doesn't have Count property and I get that error?

That would be my guess. Hopefully someone with real knowledge about it will
jump in here.

-Paul Randall