Windows Script Components  

<reference> Element

Includes a reference to an external type library.

<reference [object="progID" |guid="typelibGUID"] [version="version"]>


The program ID from which the type library can be derived, which can include a version number (for example, ADO.Recordset.2.0). This can include the explicit program ID of a type library, or the program ID of the executable (such as a .DLL) that incorporates the type library. If you use the object attribute, you do not need to specify a version attribute, because the version can be inferred from the program ID.

If the object attribute is specified, you cannot also specify a guid attribute.

The GUID of the type library to reference. If the guid attribute is specified, you cannot also specify an object attribute.
(Optional) The version number of the type library to use. It must be in the form <major version>[.<minor version>]. If a version is not specified, the default version is 1.0. If the object attribute is used to specify the type library and the version is not specified, the version is derived from the Registry key for the specified program ID. If none can be found, the default is 1.0.


Referencing a type library in your script component allows you to use constants defined in the type library in scripts. The <reference> element looks up and makes available the type library associated with a specific program ID or type library name. Type library information can be available in .tlb, .olb, or .dll files.

The <reference> element should appear inside the <component> element. If there is more than one script component in the package, the type library applies to only the script component in whose <component> element it is declared.


In the following script component fragment, referencing the type library for ADO (contained in the file MSAD015.DLL) allows you to use ADO constants such as adStateOpen in your scripts.

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

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

Function closeConnection()
   cnnState = "closed"
End Function

See Also

Referencing Other Components