Lỗi no components are defined in the file năm 2024

I'm trying to get a Windows Script Component working on and x64 development machine. Works fine on x32 bit. But can't seem to get it running, I have the same problem with both JScript and VBScript.

Here's the most simple wsc component possible. All that it does it pop up "Hello" in a message box. If you save the snippit below to a file called test_lib.wsc, you'll then be able to right click and register it. It's now available as a COM Component.






Next create the following sample vb-script and save it to a file called test.vbs

dim o
set o = createobject["TestScript.Lib"]
o.hello[]

When I run the test.vbs with cscript or wscript I always get the following. "C:\test.vbs[3, 1] Microsoft VBScript runtime error: ActiveX component can't create object: 'TestScript.Lib'"

This works perfectly fine on a 32 bit XP. Anyone got any ideas about what could be wrong?

Thanks a bunch Noel.

vy32

28.9k37 gold badges125 silver badges254 bronze badges

asked Feb 11, 2010 at 12:53

Registering the wsc from the Wndows Explorer context menu, everything worked fine for me on 64bit Windows 7.

I had problems running from a 32 bit command prompt, there I had to re-register the wsc with regsvr32 from %windir%\sysWOW64, then it ran fine with both 64 and 32 bit versions of cscript.exe, when run from either 64 or 32 command prompt.

Are you sure when you're registering the wsc, that you are using the regsvr32 from the %windir%\sysWOW64 folder?

There are two versions of regsvr32, one 32 bit [in sysWOW64], one 64 bit [in system32] they're both named regsvr32.

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.

Elements of a Basic Script Component File

  • and elements The element encloses one entire script component definition. Multiple elements can appear in the same .wsc file, and are contained within a master element.
  • 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.
  • element Encloses definitions for properties, methods, and events that your script component exposes. The definitions point to variables or functions defined in a separate block.
  • 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 , you implement the ASP interface handler and therefore get access to the ASP object model in your script component. The element is used to specify that a script component implements the COM Automation interface handler. Therefore, you don't need to create an element for the Automation handler.
    Note The script component run-time includes interface handlers for Automation [exposed using the 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.
  • 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 element, and then write the script to define them in one or more elements.
  • element Contains information about an object that you use in your script, such as another COM component.
  • 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.
  • element References a type library you want to use in script.
  • 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.

Copy Code

  This skeleton shows how script component elements are   
  assembled into a .wsc file.  
    
    
    
  [interface-specific definitions here]  
  
  • The element is optional in this example, because the file contains only one element.
  • The processing instruction includes attributes for specifying the error checking options. For details, see Checking For Errors in Script Component Files. If you do not include this element, the default options are all false.
  • A element can appear anywhere in the script component.
  • A element is not required in all cases. 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 directly instantiates the behaviors as they are detected on the page. For details about registration requirements, see the documentation for the interface handler you are implementing, and note also which host the script component will be used in.
  • A element allows you to include a type library in the script component so you can use the library's constants in your script.
  • The element encloses , , and elements. The script that defines these appears later in the script component file.
  • The element is used to make available non-default COM interfaces. For example, you can expose the ASP interface with an type such as the following:
    Copy Code The exact elements that appear inside an element depend on what interface you are implementing.
    Note The 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 element.
  • In this skeleton, there are two script elements, one for VBScript and one for JScript. If you are using only one scripting language, you do not need more than one element. Because the declaration appears at the top of the file, a CDATA section is required to make the script in the element opaque. For details, see Script Component Files and XML Conformance.
  • The element creates a reference to an object you want to use in script within the script component.
  • After creating the skeleton, fill in the elements to define the script component's functionality, depending on which interface handler you are implementing.

    Chủ Đề