开发者

Wscript.Shell Run doesn't work consistently

I'm trying to run the following bit of code in a vb6 dll:

Dim objWSShell As Object
Set objWSShell = CreateObject("Wscript.Shell")
objWSShe开发者_如何学Cll.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?


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 


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

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜