共用方式為


CreateObject Method

Creates a COM object.

                      object.CreateObject(strProgID[,strPrefix]) 

Arguments

  • object
    WScript object.

  • strProgID
    String value indicating the programmatic identifier (ProgID) of the object you want to create.

  • strPrefix
    Optional. String value indicating the function prefix.

Remarks

Objects created with the CreateObject method using the strPrefix argument are connected objects. These are useful when you want to sync an object's events. The object's outgoing interface is connected to the script file after the object is created. Event functions are a combination of this prefix and the event name. If you create an object and do not supply the strPrefix argument, you can still sync events on the object by using the ConnectObject method. When the object fires an event, WSH calls a subroutine with strPrefix attached to the beginning of the event name. For example, if strPrefix is MYOBJ and the object fires an event named OnBegin, Windows Script Host calls the MYOBJ_OnBegin subroutine located in the script. The CreateObject method returns a pointer to the object's IDispatch interface.

Tip

The Script Center Repository includes examples that use the CreateObject method that have been contributed by members of the community. In the Script Center Repository search box, type CreateObject.

Example

Description

The following VBScript code uses the CreateObject method to create a WshNetwork object:

Set WshNetwork = WScript.CreateObject("WScript.Network")

Applies To:

WScript Object

See Also

Reference

GetObject Method

ConnectObject Method

DisconnectObject Method