wscript.quit 参数在批处理错误级别不可用

发布于 2024-12-10 17:22:39 字数 705 浏览 0 评论 0原文

从批处理脚本调用的包含单行 wscript.quit(2) 的简单 VBScript 不会将 quit 参数值传递到批处理错误级别变量中,因为批处理文件仅回显默认错误级别(0)。

我最近卸载了 VB6(干净安装 VB.net 所必需的),我认为这至少可能是问题的一部分。在构建将 VBScripting 消息框的结果传递到调用批处理文件的解决方法时,我发现脚本文件系统对象 (scrrun.dll) 已因卸载而取消注册,因此有必要将其重新注册实例化对象。我想知道 wscript.exe 是否需要一些其他依赖项来让 quit 函数访问批处理错误级别变量。

我在 Dependency Walker 下为上述一行 VBScript 运行了 wscript.exe,在执行过程中收到的唯一错误消息如下:

GetProcAddress(0x755C0000 [MSCTFIME .IME],“ImeGetImeMenuItems”)从地址 0x76397354 处的“IMM32.DLL”调用并返回 NULL。错误:找不到指定的过程 (127)。

脚本以正确的退出代码终止 (2)。

提到的 dll 与 WScript 一起存在于 System32 文件夹中,并且无法注册。

我正在运行带有所有最新更新的 WinXP。

任何想法将不胜感激。

A simple VBScript containing the single line wscript.quit(2), called from a batch script does not pass the quit parameter value into the batch errorlevel variable as it should - the batch file only echos the default error level (0).

I recently uninstalled VB6 (necessary for clean installation of VB.net) and I think this may be, at least, part of the problem. In building a work-around to pass the results of a VBScripting message box to a calling batch file, I found that the scripting file system object (scrrun.dll) had been unregistered by the uninstallation and it was necessary to re-register it to instantiate the object. I'm wondering if there is some other dependency which is required by wscript.exe to give the quit function access to the batch error level variable.

I ran wscript.exe under Dependency Walker for the aforementioned one line VBScript and the only error message I got during the execution was the following:

GetProcAddress(0x755C0000 [MSCTFIME.IME], "ImeGetImeMenuItems") called from "IMM32.DLL" at address 0x76397354 and returned NULL. Error: The specified procedure could not be found (127).

The script terminated with the proper quit code (2).

The dll mentioned exists in the System32 folder with WScript and is unregisterable.

I'm running WinXP with all the latest updates.

Any ideas would be appreciated.

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

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

发布评论

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

评论(1

初熏 2024-12-17 17:22:39

Windows GUI 程序不适合控制台使用;因此它们通常会向操作系统返回 False == 0。 Wscript.exe就是这样一个程序。如果您想使用 .bat/.cmd/.exe 控制台程序中的 .vbs,请通过 Cscript.exe 调用它。

Bob 的证据:

type el.vbs
WScript.Quit 2 ' no () when calling a Sub

echo %ERRORLEVEL%
0

cscript el.vbs

echo %ERRORLEVEL%
2  <======= cscript.exe sets ERRORLEVEL

type el.vbs
WScript.Quit 2 ' no () when calling a Sub

echo %ERRORLEVEL%
0  <======= ERRORLEVEL is (re)set to 0

wscript el.vbs

echo %ERRORLEVEL%
0  <======= wscript.exe does not set ERRORLEVEL

VBScript 5.7.16599 * cscript 5.7 的 QED

更新:感谢 Bob 的评论,我发现

这个正确解释和补救措施

证据:

echo %ERRORLEVEL%
0

start /wait wscript el.vbs

echo %ERRORLEVEL%
2

所以即使是Windows GUI程序也可以/将会通过从 _tWinMain 返回适当的值来报告状态 - 您只需 /wait (分别为 .Run( sCmd, nShow, True )即可获取它。

Windows GUI programs aren't meant for console use; so they most often return False == 0 to the OS. Wscript.exe is such a program. If you want to use a .vbs from a .bat/.cmd/.exe console program, call it via Cscript.exe.

Evidence for Bob:

type el.vbs
WScript.Quit 2 ' no () when calling a Sub

echo %ERRORLEVEL%
0

cscript el.vbs

echo %ERRORLEVEL%
2  <======= cscript.exe sets ERRORLEVEL

type el.vbs
WScript.Quit 2 ' no () when calling a Sub

echo %ERRORLEVEL%
0  <======= ERRORLEVEL is (re)set to 0

wscript el.vbs

echo %ERRORLEVEL%
0  <======= wscript.exe does not set ERRORLEVEL

QED for VBScript 5.7.16599 * cscript 5.7

Update: Thanks to Bob's comment, I found

this correct explanation and remedy

evidence:

echo %ERRORLEVEL%
0

start /wait wscript el.vbs

echo %ERRORLEVEL%
2

So even Windows GUI programs can/will report status by returning an appropriate value from _tWinMain - you'll just have to /wait (resp. .Run( sCmd, nShow, True ) to pick it up.

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