If the host application requires it, you can register a Windows® Script Component as a COM component using a program such as Regsvr32.exe. Registration places information about the COM component in a public location (in Windows, registration information is stored in the Windows registry). By reading the registration information, applications can find and load the COM component.
Note Registration is not required in every case. For example, a script component that implements the DHTML Behaviors interface handler in Internet Explorer 5.0 does not need to be registered, because Internet Explorer registers the behaviors as they are detected on the page. For more details about using Behaviors, see the "Using DHTML Behaviors" topic on the Microsoft Site Builder Network (SBN) Web site. If the host application supports monikers, you can also create an instance of a script component without registering it.
When you specify registration, the most important information is:
Set Component = CreateObject("Component.MyComponent")
Note If you create a script component using the Script Component Wizard, the wizard automatically creates a program ID and class ID for you. For details, see Using The Script Component Wizard.
Registration information also includes a description and a version number.
The registration program can create a class ID for your script component when it is registered. However, it is highly recommended that you provide a class ID for the script component yourself, to ensure that your script component has the same class ID on all computers on which it is registered. Allowing the registration program to create a class ID can also cause problems if you use the script component with development tools that store class IDs. If the registration creates a new class ID each time, it will not match the ID stored by the application.
To create registration information for the script component
<registration description="My Test Component" progid="Component.TestScript" version="1" classid="{2154c700-9253-11d1-a3ac-0aa0044eb5f}"/>
Note The registration attributes can appear in any order in the <registration> element.
The script component <registration> element also allows you to include script that will be executed when the script component is registered and unregistered. For example, you can post a message that the script component has been registered.
To run script during registration and unregistration
The following example shows how to post messages when the script component is registered or unregistered.
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 description="My Test Component" progid="Component.TestScript" version="1" classid="{2154c700-9253-11d1-a3ac-0aa0044eb5f}"> <script language="VBScript"> <![CDATA[ Function register() MsgBox "Component 'My Test Component' registered." End Function Function unregister() MsgBox "Component 'My Test Component' unregistered." End Function ]]> </script> </registration>
If you are deploying your script component in a distributed environment, you can specify that the script component can be instantiated remotely. For example, you might be creating a script component designed to run on a server, but which will be called from code on a client. This scenario is possible if the client and server machines are properly configured with DCOM, which provides the mechanism for passing object pointers to the client from the server.
To register a script component for remote access
<registration description="My Test Component" progid="Component.TestScript" version="1" classid="{2154c700-9253-11d1-a3ac-0aa0044eb5f}" remotable=true/>
For more details about creating instances of a script component remotely, see Using a Script Component in an Application.
Script Component File Contents | Using The Script Component Wizard | Creating a Script Component Type Library | Checking For Errors in Script Component Files | Script Component Files and XML Conformance