1

I know there are many posts on this issue but there is a minor twist to what I need to do.

I can figure out how to create a shortcut with an argument like this:
"C:\Program Files\My App\App.exe" /s

But I need to apply the path of a file wrapped in "" as argument like this:
"C:\Program Files\My App\App.exe" "c:\Data\File.ext"
Note the double quotes.

I can't find any VBscript examples illustrating this behaviour.
This is what I've based my current script on.

@echo off

set SCRIPT="%TEMP%\%RANDOM%-%RANDOM%-%RANDOM%-%RANDOM%.vbs"

echo Set oWS = WScript.CreateObject("WScript.Shell") >> %SCRIPT%
echo sLinkFile = "%USERPROFILE%\Desktop\myshortcut.lnk" >> %SCRIPT%
echo Set oLink = oWS.CreateShortcut(sLinkFile) >> %SCRIPT%
echo oLink.TargetPath = "D:\myfile.extension" >> %SCRIPT%
echo oLink.Save >> %SCRIPT%

cscript /nologo %SCRIPT%
del %SCRIPT%
nixda
  • 27,634
Morten Kahr
  • 11
  • 1
  • 1
  • 4

2 Answers2

1

The soultion was the triple quotes:

For some reason the

echo oLink.arguments = Chr(34) & "c:\Data\File 1.ext" & Chr(34)

Makes the File 1.ext open.

mveroone
  • 1,928
user257843
  • 11
  • 1
0

Try adding

echo oLink.arguments = "c:\Data\File.ext"

Before the oLink.save.

If you find you still need to include the quotes (I don't think you would), you can triple them up in the batch file.

echo oLink.arguments = """c:\Data\File 1.ext"""

The outer-most quotes are the ones delimiting the string, and the inner doubled up double quotes are to put the double quote within the string.