Microsoft® Windows® 2000 Scripting Guide
« Previous | Next »
Although different hardware settings must be accessed through different WMI classes, the scripting approach is identical in each case:
For example, if you want a list of CD-ROM drives, you should connect to the Win32_CDROMDrive class. If you want information about display adapters, you should connect to the Win32_VideoController class.
One nice feature of WMI is the fact that no error condition occurs if you attempt to enumerate hardware that does not exist. For example, suppose you are trying to inventory tape drives, and no tape drive exists on a particular computer. This is not a problem; you will still receive a collection of the tape drives on that computer. The only difference is that the collection will have no items in it.
Of course, you do not receive any "official" notice that the computer does not have any tape drives; you have to infer this from the fact that no tape drive information was returned. To help verify that the computer does not have any tape drives, you can use the Count property to check the number of items in the collection. If the Count is 0, you can echo the message, No tape drives were found in this computer.
If the Count is greater than 0, you can then report the property values for each tape drive.
The following code sample uses the Count property to identify zero-item collections:
If colTapeDrives.Count = 0 Then Wscript.Echo
"No tape drives were found in this computer.
"Else For Each objTapeDrive in colTapeDrives Wscript.Echo objTapeDrive.Name Next End If
Listing 8.4 contains a script that retrieves the hardware inventory for a computer. In this script, information is retrieved for only a single hardware category: the pointing device. To retrieve information about additional hardware categories, the script would need to connect to each additional hardware class (for example, Win32_SoundDevice) and retrieve the appropriate property values.
To carry out this task, the script must perform the following steps:
This query returns a collection of all the pointing devices (mice, trackballs, and similar hardware) installed on the computer.
Note
Listing 8.4 Inventorying Computer Hardware
|
|
Send us your feedback | « Previous | Next » |