Blog du Tristank

So terrific that 3 of 4 readers rated it "soporific"

Blogs

WshShell.Run and Long File Names

  • Comments 2
  • Likes

I hit this the other day - when using the Wsh Shell object's Run method in VBScript, passing a long filename (LFN) tends to truncate, so:

set oShell = CreateObject("Wscript.Shell")
oShell.Run "C:\Documents and Settings\Tester\Desktop\TestFile.Doc"

will fail with a message similar to "Cannot find C:\Document".

Simple solution: Double-escape the double quotes:

oShell.Run """C:\Documents and Settings\Tester\Desktop\TestFile.Doc"""

Comments
  • the web is amazing. Thanks for the tip.

  • メモ: VBScript から Run メソッドでコマンドを実行するときの注意(括りに使う二重引用符)