Microsoft® Windows® 2000 Scripting Guide
« Previous | Next »
The third component of WMI monikers is the WMI object path. Like the security settings component, the object path component is optional. However, the object path provides a great deal of flexibility, including the ability to identify remote computers. Because of this, chances are good you will use WMI object paths whether or not you realize it. You use the WMI object path to uniquely identify one or more of the following target resources:
Set objSWbemServices = GetObject(
"winmgmts:
")
This moniker connects to the WMI service on a remote computer named atl-dc-01:
Set objSWbemServices = GetObject(
"winmgmts:\\atl-dc-01
")
Computer names are typically specified using the NetBIOS name of the computer. However, computer names can also be specified using a DNS name (for example, atl-dc-01.fabrikam.com) or an IP address (for example, 192.168.1.1).
Set objSWbemServices = GetObject(
"winmgmts:\\atl-dc-01
")
This moniker connects to the root\default namespace on atl-dc-01:
Set objSWbemServices = GetObject(
"winmgmts:\\atl-dc-01\root\default
")
Set objSWbemObject = GetObject _ (
"winmgmts:\\atl-dc-01\root\cimv2:Win32_OperatingSystem
")
Set objSWbemObject = GetObject _ (
"winmgmts:\\atl-dc-01\root\cimv2:Win32_LogicalDisk.DeviceID='C:'
")
In an object path, the computer name and the WMI namespace are separated using either forward slashes or back slashes. Both of these are valid object paths:
\\WebServer\root\cimv2
//WebServer/root/cimv2
Note
\\Webserver/root/cimv2
.If a WMI class is to be included in the object path, the class name must be separated from the namespace by a colon (:). For example, this object path connects to the Win32_Printer class:
\\WebServer\root\cimv2:Win32_Printer
Note
To bind directly to an instance of a class (for example, to bind to a particular service), you must include the class name, a dot (.), the key property of the class, and the value of that property. This object path returns only one object, representing the Alerter service:
\\WebServer\root\cimv2:Win32_Service.Name='Alerter'
A key property is a property that can be used to uniquely identify an instance. Name is a key property of Win32_Service because all services must have unique names. StartMode is not a unique property of a service because all services could, at least in theory, have the same start mode.
In other words, a connection string such as the following will fail because StartMode is not a key property of the Win32_Service class:
Set colServices = GetObject _ (
"winmgmts:\\.\root\cimv2\Win32_Service.StartMode='Auto'
")
If you attempt to run the preceding script, you will receive an "Invalid syntax" error.
Note
Classes typically have only one key property, although there are some exceptions. The Win32_NTLogEvent class has two key properties: Logfile and RecordNumber. This is because RecordNumber alone does not uniquely identify an event recorded in the event logs: Both the Application event log and the Security event log can have a record with a RecordNumber of 555. To uniquely identify an event log record, you need to specify both key properties in the object path:
\\WebServer\root\cimv2:Win32_NTLogEvent.Logfile='Application',RecordNumber=555
Send us your feedback | « Previous | Next » |