Windows Script Components  

<object> Element

Defines objects that can be referenced by script.

<object id="objID" [classid="clsid:GUID" | progid="progID"] events="true|false"/>


A name by which the object can be referenced in your script. Object ID values must begin with a letter and can include letters, digits, and underscores (_). The object ID must be unique throughout the scope of the script component. For example, if you specify the name CObj, you can reference the object in your script this way:
x = CObj.Prop1
(Optional) A reference to the class ID (GUID) under which the object has been registered. Use "clsid:" followed by the class ID (without curly brackets). Either a classid or a progid attribute must be specified. For example:
(Optional) The program ID of the object, which can be specified as an alternative to the class ID. Either a classid or a progid attribute must be specified.
(Optional) An attribute that allows you to hook events from the object. By default, events is false. If the attribute is true, you can connect to any events the object may fire. You must add an event handler for each event that is to be handled.


The <object> element provides a way to expose objects globally for use in scripting within the script component without having to use a function such as CreateObject(). Using an <object> element makes the object available with global scope, and allows scripting tools to provide statement completion for the object's members.


The following script component fragment includes an <object> element to create an object reference to the ADODB.Connection object.

Note   A CDATA section is required to make the script in the <script> element opaque. For details, see Script Component Files and XML Conformance.
<registration progid="ADOScriptlet"/>
<object id="cnn" progid="ADODB.Connection"/>
   <property name="cnnState"/>
   <method name="openconnection"/>

<script language="VBScript">
Dim cnnState
Function openconnection()
   cnn.ConnectionString = 
      "driver={SQL Server};server=myserver;uid=sa;database=pubs"
   If cnn.State = 1 Then
      cnnState = "open"
      cnnState = "closed"
   End If
End Function

See Also

Script Component File Contents