Free Source Code and Program Tips
Retrieving a class and WMI class
Note: This a part from MSDN, just for self refference. The copyright is handled by Microsoft.
The first type of object you can retrieve is a WMI class. When retrieving a WMI class, you actually retrieve a class definition: that is, a listing of the properties, qualifiers, and methods that fully describe the class. However, a class definition is for all purposes the class itself.
To retrieve a class definition in VBScript
You can retrieve the class definition with the VBScript call GetObject, but do not specify a specific instance in the object path for the class.
The following code example retrieves the class definition for the class that describes logical drives on your computer. For information on the defaults that are being used, see Using Defaults for More Concise Code.
Visual Basic and VBScript support the following syntax:
Set objinst = GetObject(“WinMgmts:Win32_LogicalDisk”)
Windows Script Host also supports:
A class or instance can also be specified, in which case the returned object is a WMI object rather than a services object.
The GetObject function provided by VBScript and JScript cannot be used when running scripts embedded within an HTML page, as Microsoft® Internet Explorer disallows the use of this call for security reasons. This function also cannot be used to create an instance of the “generic” object SWbemObject.
To retrieve a class definition in C++
Call the IWbemServices::GetObject or IWbemServices::GetObjectAsync methods to retrieve the definition of a class.
A single class can have multiple class definitions, usually when you have more than one class provider loaded into a single namespace. When a class has multiple class definitions, WMI returns the first definition discovered and the WBEM_S_DUPLICATE_OBJECTS status code.
| Print article | This entry was posted by hamo on December 17, 2006 at 6:48 pm, and is filed under Script. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |