Export (0) Print
Expand All

Retrieving and Displaying All Properties of a Managed Resource

Microsoft® Windows® 2000 Scripting Guide

One limitation of the script shown in Listing 6.23 is that it requires you to know, in advance, the names of all of the properties that you want to retrieve and display. However, what if you want to display values for all the properties of a class but you either do not know the property names or do not want to type the 40 or 50 lines of code required to display each property value? In that case, you can use the script in Listing 6.24, which automatically retrieves and displays the values of each property found in a class.

Listing 6.24 Template for Retrieving and Displaying All Properties of a Resource

  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31


strComputer = "."
strNamespace = "\root\cimv2"
strClassName = "Win32_Process"


Set objSWbemServices = _
 GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
 strComputer & strNamespace)

Set colInstances = objSWbemServices.ExecQuery("SELECT * FROM " &_
 strClassName)

Wscript.Echo "Properties of Instances of Class " & strClassName
Wscript.Echo "================================================="

iCount = 0
For Each objInstance in colInstances
 iCount = iCount + 1
 Set colProperties = objInstance.Properties_

 Wscript.Echo vbCrLf
 Wscript.Echo "******************"
 Wscript.Echo "INSTANCE NUMBER: " & iCount
 Wscript.Echo "******************"
 Wscript.Echo vbCrLf

 For Each objProperty in colProperties
 Wscript.Echo objProperty.Name & " : " & objProperty.Value
 Next
 Wscript.Sleep(2000)
Next

To use this template with other WMI classes:

  1. Set the value of strClassName to the appropriate WMI class.

  2. If necessary, set the value of strNamespace to the appropriate WMI namespace.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft