Blog du Tristank

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


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"""

  • the web is amazing. Thanks for the tip.

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