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
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>