Once you have a basic understanding of the WMI architecture, scripting with WMI is easy. In fact, once you understand how to reference, enumerate and query objects of a particular class with WMI, it is straightforward to adapt the code to work with any managed component.
To reference objects in WMI, you use a UNC-style path name. An example of how to reference the C: drive on a computer looks like the following:
The format should be easy to follow. The first part of the path
(\\dc1\) is a reference to the computer on which
the object resides. To reference the computer on which the script is
running, you can use a “.” for the
computer name. The second part (
root\CIMv2) is the
namespace the object resides in. The third part
Win32_LogicalDisk) is the class of the object to
reference. The fourth part is the key/value pairs representing the
object. Generically, the path can be shown as follows:
Now that we know how to reference WMI objects, let’s
go ahead and instantiate an object using VBScript’s
GetObject function. For
GetObject to understand that we are referencing WMI objects, we have to include one additional piece of information: the moniker. Just as we’ve been using the LDAP: and WinNT: progIDs to reference Active Directory and SAM-based objects in ADSI, we need to use the winmgmts: moniker when we ...