Choosing a Method for Binding to an Automation Object

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

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.

Set TestObject = GetObject("winmgmts:")
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")

send us your feedback Send us your feedback « Previous | Next »   


Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 635

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net