Wscript.Shell Run 无法一致工作
我试图在 vb6 dll 中运行以下代码:
Dim objWSShell As Object
Set objWSShell = CreateObject("Wscript.Shell")
objWSShell.Run strPath & "test.bat", 0, True
dll 进程挂起。无论批处理文件的内容是什么,都不会运行。我什至尝试了一个空的批处理文件,但它仍然挂起。但是,如果我尝试使用相同的代码进行此更改:
Dim objWSShell As Object
Set objWSShell = CreateObject("Wscript.Shell")
objWSShell.Run "calc", 0, True
它工作正常。我不明白为什么 exe 文件可以工作而 bat 文件不能。有什么想法吗?
I'm trying to run the following bit of code in a vb6 dll:
Dim objWSShell As Object
Set objWSShell = CreateObject("Wscript.Shell")
objWSShell.Run strPath & "test.bat", 0, True
The dll process gets hung up. The batch file will not run, no matter what its contents. I even tried an empty batch file and it still hung up. However, if I try this same piece of code, with this change:
Dim objWSShell As Object
Set objWSShell = CreateObject("Wscript.Shell")
objWSShell.Run "calc", 0, True
It works fine. I can't figure out why exe files work and bat files don't. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你不需要使用 shell 脚本,你可以让事情变得更简单。使用内置的 Shell() 函数:
同上:
You don't need to use the shell scripting stuff, you can make things simpler & use the built in
Shell()
function:Ditto for:
您需要运行 cmd.exe 并将 BAT 文件传递给它。
You need to run cmd.exe and pass your BAT file to it.
我遇到了类似问题,其中批处理文件无法直接从
WScript.Shell
运行,但我无权修改 VBScript。事实证明 .bat 扩展名存在注册表覆盖。虽然使用 COMSPEC 对我有用,但删除注册表项实际上解决的不仅仅是 WScript 问题。
I had a similar issue where batch files couldn't be run directly from
WScript.Shell
, but I didn't have access to modify the VBScript. It turns out there was a registry override on the .bat extension.While using COMSPEC worked for me, deleting the registry key actually fixed more than just the WScript problem.