wscript.quit 参数在批处理错误级别不可用
从批处理脚本调用的包含单行 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Windows GUI 程序不适合控制台使用;因此它们通常会向操作系统返回 False == 0。 Wscript.exe就是这样一个程序。如果您想使用 .bat/.cmd/.exe 控制台程序中的 .vbs,请通过 Cscript.exe 调用它。
Bob 的证据:
VBScript 5.7.16599 * cscript 5.7 的 QED
更新:感谢 Bob 的评论,我发现
这个正确解释和补救措施
证据:
所以即使是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:
QED for VBScript 5.7.16599 * cscript 5.7
Update: Thanks to Bob's comment, I found
this correct explanation and remedy
evidence:
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.