• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

VBScript WSH: counting object items

PopeKevinI

2[H]4U
Joined
Mar 25, 2002
Messages
2,880
This is the code I'm starting with, modified from Scriptomatic 2.0

Code:
On Error Resume Next

strComputer = "."
WScript.Echo "Computer: " & strComputer

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_VideoController", "WQL", _
                                       wbemFlagReturnImmediately + wbemFlagForwardOnly)

For Each objItem In colItems
   WScript.Echo "PNPDeviceID: " & objItem.PNPDeviceID
Next
The For loop is just proof of concept. Before that, what I want to do (for starters) is echo the number of devices found. I thought I'd be able to do that using colItems.Count as I've done with other objects, but that didn't work.

edit: to be clear, I need to get the number of query results in colItems.

I know that I could use the for look and a simple x=x+1 approach, but I'd like to use something more elegant and learn the proper way of coding this.

What this is about: This script is going to make decisions based on the number of display devices reported (1,2,3, or 4) as well as the VEN and DEV codes that are the results of the query. It's a result of us having 1,500+ computers that get imaged once a year and need to have various video configurations, including two incompatible versions of ATI's CCC.
 
Last edited:
I know I'm almost two weeks late to this party but I see you had no replies. I don't know much regarding WMI stuff but you can't call the Count property because you specified the "wbemFlagForwardOnly" flag. Doing so eliminates the memory for that object since you'll be processing it with your For Each loop. wbemFlagForwardOnly is great when grabbing a large collection of objects but otherwise, the savings are probably trivial.

http://msdn.microsoft.com/en-us/library/aa393763(VS.85).aspx
http://msdn.microsoft.com/en-us/library/aa392301(VS.85).aspx
 
Back
Top