创建简单的“Windows 脚本组件”时出现问题在 Windows 7 上

发布于 2024-08-21 17:22:40 字数 1065 浏览 1 评论 0原文

我正在尝试让 Windows 脚本组件在 x64 开发机器上运行。在 x32 位上运行良好。但似乎无法运行它,我对 JScript 和 VBScript 都有同样的问题。

这是最简单的 wsc 组件。它所做的一切都是在消息框中弹出“Hello”。如果将下面的代码片段保存到名为 test_lib.wsc 的文件中,则可以右键单击并注册它。现在它可以作为 COM 组件使用。

<?xml version="1.0"?>
<component>
<?component error="true" debug="true"?>
<registration
    description="Test Script Library"
    progid="TestScript.Lib"
    version="1.00"
    classid="{314042ea-1c42-4865-956f-08d56d1f00a8}"
>
</registration>
<public>
  <method name="Hello">
  </method>
</public>
<script language="VBScript">
<![CDATA[
Option Explicit
Function Hello()
    MsgBox("Hello.")
End Function
]]>
</script>
</component>

接下来创建以下示例 vb 脚本并将其保存到名为 test.vbs 的文件中。

dim o
set o = createobject("TestScript.Lib")
o.hello()

当我使用 cscript 或 wscript 运行 test.vbs 时,我总是得到以下结果。 “C:\test.vbs(3, 1) Microsoft VBScript 运行时错误:ActiveX 组件无法创建对象:'TestScript.Lib'”

这在 32 位 XP 上运行得非常好。 有人对可能出什么问题有任何想法吗?

非常感谢 诺埃尔.

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.

<?xml version="1.0"?>
<component>
<?component error="true" debug="true"?>
<registration
    description="Test Script Library"
    progid="TestScript.Lib"
    version="1.00"
    classid="{314042ea-1c42-4865-956f-08d56d1f00a8}"
>
</registration>
<public>
  <method name="Hello">
  </method>
</public>
<script language="VBScript">
<![CDATA[
Option Explicit
Function Hello()
    MsgBox("Hello.")
End Function
]]>
</script>
</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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寻找我们的幸福 2024-08-28 17:22:40

从 Wndows Explorer 上下文菜单注册 wsc,在 64 位 Windows 7 上一切正常。

我在 32 位命令提示符下运行时遇到问题,必须使用 regsvr32 从 %windir%\ 重新注册 wsc sysWOW64,那么当从 64 或 32 命令提示符运行时,它可以在 64 位和 32 位版本的 cscript.exe 上正常运行。

您确定在注册 wsc 时使用的是 %windir%\sysWOW64 文件夹中的 regsvr32 吗?

regsvr32 有两个版本,一种是 32 位(在 sysWOW64 中),一种是 64 位(在 system32 中),它们都被命名为 regsvr32。

使困惑?加入我们其他人吧 :)

这里有一个很好的链接,突出显示了 64 位 Windows 上的一些问题: 全部相同但又截然不同

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.

Confused? Join the rest of us :)

Here's a good link that Highlights some gotchas on 64bit Windows: All the same yet very different

酒与心事 2024-08-28 17:22:40

您需要确保使用 32 位版本的 WScript 或 CScript 运行它。

默认情况下,它将以 64 位版本运行,并且无法加载 32 位组件。

32 位版本的 WScript 和 CScript 位于 "%SystemRoot%\SysWOW64\ 中,

我使用 RegEdit 添加一个新的注册表项:-

HKEY_CLASSES_ROOT\VBSFile\Shell\Open32\Command

并为其指定默认值:-

"%SystemRoot%\SysWOW64\WScript.exe" "%1" %*

文件的上下文菜单上提供了一个 Open32 条目。

这在VBS 执行时,您需要确保 CSript 的路径获取 SysWOW64 文件夹版本。

You need to ensure that the you run it with the 32 bit version of WScript or CScript.

By default it will run with the 64 bit version and it won't be able to load 32 bit components.

The 32bit versions of WScript and CScript are found in "%SystemRoot%\SysWOW64\

I add a new registry key with RegEdit:-

HKEY_CLASSES_ROOT\VBSFile\Shell\Open32\Command

and give it the default value of:-

"%SystemRoot%\SysWOW64\WScript.exe" "%1" %*

This gives me a Open32 entry on the context menu of a VBS file.

For CScript execution you will need to ensure the path to CSript gets the SysWOW64 folder version.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文