views:

928

answers:

1

I have a Windows shell script that opens an application. I'd like to modify it to make it open a file automatically upon opening the application.

I know it uses VBscript but I'm not familiar with the language; all the tutorials I found just talked about using VBS for web pages, not for Windows scripts. I know the syntax is different because I get error messages.

The best "solution" I found was to simply add the file path at the end of the run statement using the "&" symbol, but Windows pops up an error saying the file couldn't be found. Am I missing something?

+4  A: 

You need to quote the filename so that any spaces in the path don't cause problems.

Instead of just using & filename to append the filename, use: & Chr(34) & filename & Chr(34)

This behaviour will also rely on the application accepting a file to open on the command line, which whilst common isn't mandatory. An alternative approach would just be to try and execute the file directly using Shell.Execute. This is equivalent to double clicking the file in explorer and should launch the application registered to handle that filetype.

Rob Walker