WshShell.Run and Long File Names

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 (2)

  1. Anonymous says:

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

  2. Dan Lenehan says:

    the web is amazing. Thanks for the tip.

Skip to main content