A. To read WMI information, you must write code that connects to the WMI management object, then runs a query against it. Remember, WMI has multiple classes of information, so you need to query the correct class to retrieve the desired information. These classes are documented in the WMI software development kit (SDK); an online version of the SDK is available here.
The following sample script, which you can download at http://www.windowsitpro.com/content/content/45830/compquery.zip, queries a computer's model and serial number. This information is located in two separate classes, so you need to use two queries.
Dim objWMI : Set objWMI = GetObject("winmgmts:") Dim colSettingsComp : Set colSettings = objWMI.ExecQuery("Select * from Win32_ComputerSystem") Dim colSettingsBios : Set colSettingsBios = objWMI.ExecQuery("Select * from Win32_BIOS") Dim objComputer, strModel, strSerial For Each objComputer in colSettings strModel = objComputer.Model Next For Each objComputer in colSettingsBios strSerial = objComputer.SerialNumber Next wscript.echo strModel wscript.echo strSerial
To execute the script from a command line, save the previous script as wmi.vbs, and run this query:
cscript wmi.vbsYou'll see the following on-screen messages: Microsoft (R) Windows Script Host Version 5.6 Copyright (C) Microsoft Corporation 1996-2001. All rights reserved. Latitude D800 2TVKQ51 You can change the code to query any type of information that WMI is aware of.