7
votes

This is what I have and can not get the bat to run, if I move the bat to a folder without spaces in the name it works. My problem is that the actual bat is in a folder with spaces, so I need this to work.

Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("%comspec% /K C:\Program Files\ping.bat"), 1, True
4

4 Answers

6
votes

You need to quote the file specification:

Run("%comspec% /K ""C:\Program Files\ping.bat""")
2
votes

I had a similar problem with a directory path in a VBScript that had empty spaces:

E.g.

The following did not work:

objShell.Run("C:\Program Files\NetBeans 8.0.2\bin\netbeans64.exe") 

I simply included two extra double quotations on either side of the path and it worked for me:

objShell.Run("""C:\Program Files\NetBeans 8.0.2\bin\netbeans64.exe""")
0
votes

Try this one

Set objShell = WScript.CreateObject("WScript.Shell")
strCommand = chr(34)&"%comspec% /K C:\Program Files\ping.bat"&chr(34)
objShell.Run strCommand,1,True
-2
votes

I know that this is an old question, but I found a fix that works for me.
It's the double quotes you need.
Try below:

objShell.Run("%comspec% /K " & """C:\Program Files\ping.bat""""), 1, True);