直接用Script Control(推荐)
或者用PROGID为"JScript"返回IActiveScript(强烈不推荐,过程复杂)

解决方案 »

  1.   

    哦。。
    我自己做了个也忘记了。
    http://lostinet.d2g.com/temp/RunJScriptWSC.zip
      

  2.   

    把wb.js的代码封装在*.wsc的文件中,然后注册,就可以当作ActiveX的控件来调用了。{……-……}
    给一个*.wsc例子:
    <?XML version="1.0"?>
    <package>
    <component id="component1">
    <registration progid="Component.FrontEnd"/>
    <public>
       <property name="math"/>
       <property name="WScript0"/>
    </public>
    <script language="JScript">
    <![CDATA[
    var math = createComponent("component2");
    var WScript0 = new ActiveXObject("WScript.Shell");
    ]]>
    </script>
    </component><component id="component2">
    <registration progid="Component.Math"/>
    <public>
       <method name="add"/>
       <method name="multiply"/>
    </public>
    <script language="JScript">
    <![CDATA[
    function add(n1, n2){
       return n1+n2;
    }
    function multiply(n1, n2){
       return n1*n2;
    }
    ]]>
    </script>
    </component>
    </package>
    下面是利用上边的注册过后的测试脚本:
    ' Creates instance of first script component.
    set o1 = CreateObject("Component.FrontEnd")' Invokes the second script component's functions directly.
    msgbox(o1.WScript0.SpecialFolders("Desktop"))
    'msgbox(o1.WScript0)
    msgbox(o1.math.add(3,5))
    'msgbox(o1.math.multiply(3,5))' Creates a second object that references the math method directly.
    Set o2 = o1.math
    'msgbox(o2.add(4,5))
    'msgbox(o2.multiply(4,5))