Kushal
Kushal

Reputation: 3168

Problem executing a .bat file at a path where folder name has spaces, in VB6

I'm trying to execute a .bat file in VB6 (silent window mode) with following code.

Set WshShell = CreateObject("WScript.Shell")

cmds = WshShell.RUN("E:\My Folder\RunScript.bat", 0, True)

Set WshShell = Nothing

Things work absolutely fine if there's no space in 'My Folder'.but call fails if such a space is encountered. How can I solve this issue?

Upvotes: 2

Views: 2045

Answers (3)

Pekka
Pekka

Reputation: 449515

I don't know much about WSH, but try adding single quotes:

cmds = WshShell.RUN("'E:\My Folder\RunScript.bat'", 0, True)

They may do the trick if RUN passes the command on to some other instance.

Alternatively, if you want to go the ugly route, you could try finding out the 8.3 name of the directory (using dir), and specify that.

Upvotes: 1

Davide
Davide

Reputation: 602

Try doing this:

cmds = WshShell.RUN("""E:\My Folder\RunScript.bat\""", 0, True)

Upvotes: 4

Philipp
Philipp

Reputation: 11813

have you tried

cmds = WshShell.RUN("""E:\My Folder\RunScript.bat""", 0, True)

?

Upvotes: 0

Related Questions