Sunday, 17 December 2017

windows - How to create a shortcut using a batch script?



How can I create a shortcut to the file D:\myfile.extension on the Desktop using a batch script?



Answer



You can achieve without external tools this by creating a temporary VBScript:


@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%

(Idea taken from here.)


This will create myshortcut.lnk on the Desktop, pointing to D:\myfile.extension.


You can supply additional properties before saving the link by modifying the following values:


oLink.Arguments
oLink.Description
oLink.HotKey
oLink.IconLocation
oLink.WindowStyle
oLink.WorkingDirectory

Consult How to create a desktop shortcut with the Windows Script Host to see a few examples.


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...