Export (0) Print
Expand All

Choosing a Method for Binding to an Automation Object

Microsoft® Windows® 2000 Scripting Guide

Binding to an Automation object is actually quite easy; the hardest part involves knowing how to bind to that object (that is, do you use the GetObject method or the CreateObject method?). For the most part, this depends on the object you are binding to; however, some general guidelines for binding to Automation objects are listed in Table 2.20.

Table 2.20 Methods for Binding to Automation Objects

To Perform This Task

Use This Method

Bind to WMI or ADSI.

VBScript GetObject and the appropriate moniker.

A moniker is an intermediate object that makes it possible to locate, activate, and create a reference to Automation objects. Both WMI and ADSI are accessed using monikers; this allows your script to locate WMI and ADSI objects without having to know the physical location of these objects. Monikers are typically used to bind to COM objects that reside outside the file system.

Bind to a new instance of an Automation object.

VBScript CreateObject and the appropriate ProgID.Set TestObject = CreateObject("Word.Application")

Bind to an existing instance of an Automation object.

VBscript GetObject and the appropriate ProgID.Set TestObject = GetObject("Word.Application")

Bind to an Automation object by using an existing file.

VBScript GetObject and the appropriate file path.Set TestObject = GetObject("c:\scripts\test.xls")

Bind to a new instance of an Automation object, with the ability to receive event notifications from that object.

Wscript CreateObject, the appropriate ProgID, and an event mapping variable.Set TestObject = Wscript.CreateObject _ ("Word.Application", "Word")

Bind to an existing instance of an Automation object, with the ability to receive event notifications from that object.

Wscript GetObject, the appropriate ProgID, and an event mapping variable.Set TestObject = Wscript.GetObject _ ("Word.Application", "Word")

Bind to a new instance of an Automation object on a remote computer.

VBScript CreateObject, the appropriate ProgID, and the name of the remote computer.Set TestObject = CreateObject _ ("Word.Application", "atl-dc-01")

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft