tags:

views:

103

answers:

2

I'm trying to run the following bit of code in 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?

+2  A: 

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

objWSShell.Run "%COMSPEC% /c " & strPath & "test.bat", 0, True
Bob Riemersma
Thanks so much! That did the trick.
Joe Majsterski
+1  A: 

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 
Alex K.
I agree with this, and it can be enhanced using a "Shell and wait" technique if required. Google should turn up some examples readily.
Bob Riemersma
I'll keep this in mind as well.
Joe Majsterski