How to create a desktop shortcut from a batch file
9,783
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.
Related videos on Youtube
Author by
Morten Kahr
Updated on September 18, 2022Comments
-
Morten Kahr over 1 year
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%
-
Morten Kahr over 10 years@techie007 - I am aware. I am calling a temporary VBScript from within the batch file. Something like this superuser.com/a/455383/257686
-
vembutech about 9 yearsHere check this discussion stackoverflow.com/questions/346107/…
-
-
nixda over 10 years@MortenKahr Usually I use Chr(34) instead of double quotes for the outer pair as shown on stackoverflow
-
Morten Kahr over 10 years@nixda So echo oLink.arguments = Chr(34) c:\Data\File 1.ext Chr(34) ?
-
nixda over 10 years@MortenKahr
echo oLink.arguments = Chr(34) & "c:\Data\File 1.ext" & Chr(34)
-
Ƭᴇcʜιᴇ007 over 10 yearsAdjusted my answer (after testing).
-
Morten Kahr over 10 years@nixda (techie007) I'll try both in the morning. Thanks a lot