Microsoft® Windows® Script Component Script Component File Contents |
Script Component Tutorial Previous Next |
Windows® Script Component files are XML (Extensible Markup Language) that are much like HTML files, but contain special elements that define the script component and its behavior. The elements used for defining script components are not HTML tags, but are XML elements specifically used for script component definitions.A basic script component file contains these elements:
- <component> and <package> elements The <component> element encloses one entire script component definition. Multiple <component> elements can appear in the same .wsc file, and are contained within a master <package> element.
- <registration> element Includes information used to register your script component as a COM component. This element might not be required if the host application (such as Microsoft® Internet Explorer 5.0) does not directly use the Windows registry when creating an instance of the script component.
- <public> element Encloses definitions for properties, methods, and events that your script component exposes. The definitions point to variables or functions defined in a separate <script> block.
- <implements> element Specifies the COM interface handler for the script component, which determines what type of COM component the script component will be. For example, by specifying <implements type=ASP>, you implement the ASP interface handler and therefore get access to the ASP object model in your script component.
The <public> element is used to specify that a script component implements the COM Automation interface handler. Therefore, you don't need to create an <implements> element for the Automation handler.
Note The script component run-time includes interface handlers for Automation (exposed using the <public> element), for ASP, and for Internet Explorer 5.0 DHTML Behaviors. Other interface handlers are available as external DLLs. For more information about additional interface handlers and script components, see the Microsoft Scripting Technologies Web site.
- <script> element Contains the script used to implement the logic of your script component, depending on what type of COM component you are creating. For example, if you are creating a COM Automation component, you declare properties, methods, and events in a <public> element, and then write the script to define them in one or more <script> elements.
- <object> element Contains information about an object that you use in your script, such as another COM component.
- <resource> elements Contain values that should not be hard-coded into script component code. Resource elements can include information that might change between versions, strings that might be translated, and other values.
- <reference> element References a type library you want to use in script.
- <comment> elements Contain text that is ignored when the script component is parsed and executed.
Note If you are concerned that the .wsc files you create contain XML that conforms to XML standards, you can specify that the script component's XML parser check the XML syntax. For example, this is useful if you think you might someday use an XML editor to work with your files. Otherwise, however, it is not usually a concern. For more details, see Script Component Files and XML Conformance.
Skeleton Script Component File
The following example illustrates how to construct a script component file.<?XML version="1.0"?> <package> <?component error="true" debug="true"?> <comment> This skeleton shows how script component elements are assembled into a .wsc file. </comment> <component id="MyScriptlet"> <registration progid="progID" description="description" version="version" clsid="{00000000-0000-0000-000000000000}"/> <reference object="progID"> <public> <property name="propertyname"/> <method name="methodname"/> <event name="eventname"/> </public> <implements type=COMhandlerName id=internalName> (interface-specific definitions here) </implements> <script language="VBScript"> <![CDATA[ dim propertyname Function methodname() ' Script here. End Function ]]> </script> <script language="JScript"> <![CDATA[ function get_propertyname() { // Script here. } function put_propertyname(newValue) { // Script here. fireEvent(eventname) } ]]> </script> <object id="objID" classid="clsid:00000000-0000-0000-000000000000"> <resource ID="resourceID1">string or number here</resource> <resource ID="resourceID2">string or number here</resource> </component> </package>
Tip In XML, you can specify elements without content (attributes only), such as the <property> and <method> elements in the previous example, by closing the element with />.
Note that:
<implements type="ASP" id="iASP">
The exact elements that appear inside an <implements> element depend on what interface you are implementing.
Note The <implements> element is shown here with an id attribute. However, this attribute is optional, except in cases where you must disambiguate objects or variables. For details, see the <implements> element.
After creating the skeleton, fill in the elements to define the script component's functionality, depending on which interface handler you are implementing.