Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBS with Space in File Path

Tags:

vbscript

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
like image 737
WACs Avatar asked Jan 16 '13 14:01

WACs


2 Answers

You need to quote the file specification:

Run("%comspec% /K ""C:\Program Files\ping.bat""")
like image 79
Ekkehard.Horner Avatar answered Oct 31 '22 06:10

Ekkehard.Horner


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""")
like image 25
Mark Burleigh Avatar answered Oct 31 '22 05:10

Mark Burleigh