Microsoft® Windows® 2000 Scripting Guide
« Previous | Next »
Automation objects allow you to use their capabilities within your scripts. This enables you to create more powerful and more useful scripts than you could create if you were restricted to the functionality of the scripting language. For example, it is impossible to draw a chart or graph by using VBScript alone. Through Automation, however, you can borrow the capabilities of Microsoft Excel and easily add a chart or graph to, say, a Web page.
Automation objects typically expose both methods and properties. (However, there is no requirement for them to expose either.) Methods are equivalent to the actions that the object can perform. For example, although the script in Listing 2.2 is only three lines long, it uses Automation to access the methods of two different COM objects and thus performs two different actions. These two methods are:
After you have created a reference to an object, you can call the methods of that object using dot notation. Dot notation is so named because you call a method by typing the name of the variable that references the object, a period (or dot), and the name of the method. (Depending on the method, you might also type method parameters.) Generally, dot notation uses the following syntax:
ObjectReference.MethodName
For example, in the following line of code, the SWbemServices Get method call is written in dot notation.
Set objLogicalDisk = objWMIService.Get(
"Win32_LogicalDisk.DeviceID='c:'
")
The parts of the SWbemServices Get method call are shown in Table 2.1.
Table 2.1 Parts of the SWbemServices Get Method Call
Item | Description |
---|---|
ObjWMIService | Object reference. |
. | Dot (separates the object reference and the name of the method). |
Get | Method name. |
("Win32_LogicalDisk.DeviceID= c: ") | Method parameter. For the Get method, this can be read as, "Get the instance of the Win32_LogicalDisk class where the DeviceID is equal to C:." |
Note
Msgbox objLogicalDisk.FreeSpace
Send us your feedback | « Previous | Next » |