Winscripter
  WSH
  Forums
  Downloads
  Books
  Links
  Amazon




Login
Register

© winscripter.com
1998-2004







Howto: Use Long File Names

Posted by on Sunday, January 18, 2004 (PST)

Howto: Use long file names with WSH. Including file names that include spaces.

Problem
I get strange behavior when trying reference long file names. For example when I try to run a program using WScript.Shell, I get errors and the application does not run.

var shell = WScript.CreateObject( "WScript.Shell" );
var rst = shell.Run( "c:\\program files\\plus!\\microsoft internet\\iexplore.exe", 1, true );

Solution
Wrap the path to the file in quotes. In JScript, you use the backslash character to escape special characters. We want to put a set of double quotes within an existing set of double quotes and need to escape the quotes inside using \".

var shell = WScript.CreateObject( "WScript.Shell" );
var rst = shell.Run( "\"c:\\program files\\plus!\\microsoft internet\\iexplore.exe\"", 1, true );



WSH and ADSI Administrative Scripting


Winscripter   |  WSH   |  Forums   |  Downloads   |  Books   |  Links   |  Amazon