Wscript.Shell Run 无法一致工作

发布于 2024-09-16 04:08:42 字数 438 浏览 9 评论 0原文

我试图在 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 技术交流群。

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

发布评论

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

评论(3

丘比特射中我 2024-09-23 04:08:42

你不需要使用 shell 脚本,你可以让事情变得更简单。使用内置的 Shell() 函数:

shell environ$("COMSPEC") & " /C c:\xxx\yyy.bat", vbNormalFocus 

同上:

shell "calc", vbNormalFocus 

You don't need to use the shell scripting stuff, you can make things simpler & use the built in Shell() function:

shell environ$("COMSPEC") & " /C c:\xxx\yyy.bat", vbNormalFocus 

Ditto for:

shell "calc", vbNormalFocus 
手心的海 2024-09-23 04:08:42

您需要运行 cmd.exe 并将 BAT 文件传递​​给它。

objWSShell.Run "%COMSPEC% /c " & strPath & "test.bat", 0, True

You need to run cmd.exe and pass your BAT file to it.

objWSShell.Run "%COMSPEC% /c " & strPath & "test.bat", 0, True
一身软味 2024-09-23 04:08:42

我遇到了类似问题,其中批处理文件无法直接从 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.

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