开发者

VB script want to run .bat file from VB

I am try to run the go.bat from VB but when I run the script I get: :cant find specific file

but from the cmd window the file go.bat exist. what the problem?

Dim MyShell

Dim shell_cmd

  shell_cmd = "C:\Program Files\dir1\dir2\wizard\go.bat"

  set MyShell = CreateObject("WScript.Shell")

  MyShell.Run shell_cmd, 1, 1

开发者_如何学运维from cmd window

C:\Program Files\dir1\dir2\wizard>go.bat


Your batch file's full path contains spaces, so you need to enclose it in double quotes, like this:

shell_cmd = """C:\Program Files\dir1\dir2\wizard\go.bat"""

or

shell_cmd = Chr(34) & "C:\Program Files\dir1\dir2\wizard\go.bat" & Chr(34)


not sure if you knew but in vb you can use the Shell function:

http://msdn.microsoft.com/en-us/library/xe736fyk(VS.71).aspx

(seems easier than what you're using)

I don't know why you get this message, but the two paths you mention are in fact different:

C:\Program Files\dir1\dir2\wizard\go.bat
C:\Program Files\dir1\dir2\wizard>go.bat
                                 ^
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜