WshShell.Run and Long File Names

Published 18 March 04 01:06 PM | tristank 

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

# Dan Lenehan said on April 2, 2004 10:01 AM:
the web is amazing. Thanks for the tip.
# システム管理な雑記 -- Sleeve notes of a sysadmin -- said on August 16, 2004 7:18 AM:
メモ: VBScript から Run メソッドでコマンドを実行するときの注意(括りに使う二重引用符)
New Comments to this post are disabled

Search

This Blog

Syndication

Page view tracker