Returning All Properties of All Instances of a Class

Microsoft® Windows® 2000 Scripting Guide

The simplest WQL query is one that retrieves all properties of all instances of a class. This is done simply by:

  1. Using the asterisk (*) to indicate that all properties should be retrieved.

  2. Specifying the name of the class.

For example, this query returns all properties of all services installed on a computer:

"SELECT * FROM Win32_Service"

The advantage of using a SELECT * query is that it is quick and easy; the disadvantage is that it might return far more data than you need. In some cases, the difference might be negligible. For example, a query that returns all properties of all physical disk drives installed on a computer returned 808 bytes of data; a query that specified only the Name property returned 145 bytes of data. The SELECT * query completed in less than 2 seconds; the SELECT Name query completed in less than 1 second. In practical terms, there is no real difference between the scripts.

In other cases, however, the difference can be more dramatic. A script that returned all properties of all threads running on a computer required approximately 7 seconds to complete and returned 105 kilobytes (KB) of data. A script that returned only the thread handle required less than 1 second to complete and returned 6 KB of data. Although the time difference is not substantial, the difference in the amount of data might be important, particularly if you are running the script across the network.

The script in Listing 6.18 includes a standard WQL query that returns all properties of all services installed on a computer.

Listing 6.18 Returning All Properties of All Instances of a Class

  
1
2
3
4
5
6
7
8
9
10
strComputer = "."
Set objSWbemServices = _
 GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colServices = _
 objSWbemServices.ExecQuery("SELECT * FROM Win32_Service")
For Each objService In colServices
 Wscript.Echo objService.Name
Next