WACs
WACs

Reputation: 101

VBS with Space in File Path

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

Upvotes: 8

Views: 40423

Answers (4)

user1328876
user1328876

Reputation:

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""")

Upvotes: 3

Tamati
Tamati

Reputation: 9

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);

Upvotes: -3

Amol Chavan
Amol Chavan

Reputation: 3990

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

Upvotes: 1

Ekkehard.Horner
Ekkehard.Horner

Reputation: 38775

You need to quote the file specification:

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

Upvotes: 9

Related Questions