user1055650
user1055650

Reputation: 427

VBScript: Opening a file parameter that has spaces in it's name

Im writing a small VBScript that i will pass a file path to. It works fine when the file name has no spaces but not when it does.

As far as I can tell, this is the offending line:

If util.Run("c:\program files (x86)\microsoft office\office14\PPTVIEW.exe " & WScript.Arguments(1)) = True Then
...perfomrm tasks...
End If

I have tried putting quotes around WScript.Arguments(1) but i still get errors. Any ideas on how I can get it to work?

Upvotes: 0

Views: 6410

Answers (2)

fan711
fan711

Reputation: 716

Following code sets the path of the executable as well as the parameters inside quotes:

If util.Run("""c:\program files (x86)\microsoft office\office14\PPTVIEW.exe"" """ & WScript.Arguments(1) & """") = True Then
...perfomrm tasks...
End If

Upvotes: 1

Antagony
Antagony

Reputation: 1780

You need to insert quotes to each end of the file path string – the existing quotes just inform the script engine that it contains a string. You can do this by appending Chr(34) or by adding two double quotes, like so:

If util.Run("""c:\program files (x86)\microsoft office\office14\PPTVIEW.exe"" " &    WScript.Arguments(1)) = True Then
    ...perfomrm tasks...
End If

Upvotes: 3

Related Questions