LISTING A: The QueryInstances Routine Sub QueryInstances(objClass,Properties,Conditions) If Conditions = "None" Then strSelect = "Select " & Properties & " From " & objClass Else strSelect = "Select " & Properties & " From " & objClass & _ " Where " & Conditions End If Set objClassName = _ objWMIService.ExecQuery _ (strSelect,,wbemFlagReturnImmediately + wbemFlagForwardOnly) intCounter = 0 ' You can use the following code to determine the number of ' items in the sWbemObjectSet, but it's processor intensive ' and means that you can't use a semisynchronous call ' because the count property doesn't work with ' wbemFlagForwardOnly. ' WScript.Echo "# of items in collection: " & objClassName.Count For Each objComponent in objClassName If intCounter = 0 Then objFile.WriteLine(HR) objFile.WriteLine(Mid(objClass,7) & ":") End If For Each objProperty in objComponent.Properties_ ' Start by verifying that there's a value in the property. ' If not, performing the evaluation in this loop isn't necessary. If ISNull(objProperty.Value) Then objFile.WriteLine(objProperty.Name & ": Not available") Else If objProperty.CIMType <> wbemCimtypeUint32 And _ objProperty.CIMType <> wbemCimtypeUint64 And _ objProperty.CIMType <> wbemCimtypeSint64 Then objFile.WriteLine(objProperty.Name & ": " & _ objProperty.Value & " " & _ GetUnits(objClass,objProperty.Name)) Else strUnits = GetUnits(objClass,objProperty.Name) intValue = _ SizeFormat(objProperty.Name,objProperty.Value,strUnits) objFile.WriteLine(objProperty.Name & ": " & intValue) End If End If intCounter = intCounter + 1 Next If intCounter > 1 Then objFile.WriteLine(HR) Next objFile.WriteLine(HR) objFile.WriteLine() End Sub