PDA

View Full Version : WSH LFN, ARGHH! (W98)



nerus
06-10-2002, 11:11 PM
Ok, I'm pretty new to this vbscript so please forgive me for such a dumb question. How do I make this work plz...

Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.Run("c:\Program Files\test.vbs")

Very basic vbscript, I simply want to run another application which is located in c:\program files but it wont' run it says "The system cannot find the specified file" everytime. It has to do with the space in Program Files cause it works if I rename it without spaces. So in other words, how do I deal with long file names with spaces when program whs with vbscript?? Please help, thanks!

Andy-S
06-11-2002, 01:53 PM
Just change the Program Files to Progra~1. It worked for me in W2K.

Cheers
Andy

nerus
06-11-2002, 02:47 PM
OMG, YOU ARE A GOD!!!! Thanks sooo much Andy-S!! =)

Andy-S
06-11-2002, 03:17 PM
No problems. Glad to help.

Cheers
Andy

Jama
06-11-2002, 11:23 PM
Because quotation marks are removed before the string is passed to WshShell.Run, you can’t use a file with spaces in its name or path. To work around this, you can either use the file’s short name “~”, or add quotes at run time.

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.run chr(34) & "c:\Program Files\test.vbs" & chr(34), 1, True

“chr(34)” is the ASCII character code for double quotes. For a full list, <a target="_blank" href=http://www.asciitable.com/> click here. </a>

The second argument is the state of the window of the program being run. 1 means run the program in visible mode. For other options <a target="_blank" href=http://www.devguru.com/Technologies/wsh/quickref/wshshell_Run.html> click here. </a>

The third argument tells the script weather to wait for your program to finish or not before executing the next line.
True means the script should wait.

Jama