SHORTCUT.exe

Create a windows shortcut (.LNK file) Originally in the NT4 Server Resource Kit, this utility fails under Windows 10.
A good free alternative is shortcut.exe from OptimumX.com [Archive.org mirror].

Shortcuts can also be created using VBScript or PowerShell see the examples below.

Syntax
      SHORTCUT [options]

Key
   -t target    : The path and file name of the application/document to open.
   -a arguments : The arguments passed when the shortcut is used.
   -d directory : The folder to start the application in.
   -i iconfile  : The file the icon is in.
   -x index     : The index into the icon file.
   -n name      : The path and file name (.LNK) of the shortcut file.
   -c           : Change existing shortcut.
   -r           : Resolve broken shortcut.
   -f           : Force overwrite of an existing short cut.
   -s           : Make shortcut simple (don’t use LinkResolve).
   -l logfile   : Save any error messages in the specified file.
   -u [spec]    : ECHO the contents of an existing shortcut. 
                  'all' is the same as 'natdix' but the letters 
                  of 'natdix' specify the options to be exported
                  The same option can be specified more than once e.g. -u natn

Shortcut Icons

Any DLL or other icon resource iconfile can be used as the source for a custom shortcut icon.
If you will be transferring the Shortcut file to another machine, the iconfile must be in a location that is available to that machine.
The index selects a specific icon within the file.

The following classic Icon Resource files are available on all Windows 10 and 11 machines:
%SystemRoot%\SystemResources\shell32.dll.mun
%SystemRoot%\SystemResources\imageres.dll.mun

Sample shell32.dll index numbers:
shell32.dll icon samples
Sample imageres.dll index numbers:
imageres.dll icon samples

Shortcut Auto LinkResolve

By default shortcuts will include the machine name of the destination, even for a local file like C:\MyFile.doc
This is not immediately visible until the shortcut file is copied to another machine, the shortcut target will then be automatically updated to point back to \\Machine1\c$\MyFile.doc
To turn this behaviour off add a DWORD value of 1 to the registry (before creating the shortcut):

HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer
"LinkResolveIgnoreLinkInfo"=1

Shortcut NTFS file system tracking

If a shortcut to a file breaks because the destination file has moved, then by default Windows will attempt to automatically locate the shortcut destination by performing a search or matching file properties.
This can be turned on or off via the Group Policy Do not use the tracking-based method when resolving shell shortcuts or directly in the registry:

HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer
NoResolveTrack

0 = disabled, 1 = enabled (REG_DWORD)

Internet Shortcuts

Unlike file/folder shortcuts, Favourite (.URL) files are simple text files which you can create with a text editor or a couple of ECHO statements, they will open in the default browser:

Echo [InternetShortcut] > demo.url
Echo URL=https://ss64.com/ >> demo.url

Internet Explorer Pinned .website links

An IE Pinned link is a file saved with a .website extension. These are deprecated and will open in Microsoft Edge when IE 11 is disabled.

Edge Shortcuts

If Edge is not your default browser, but you want to open a web page using Edge, set the Shortcut Target to a path like the following:

%windir%\explorer.exe microsoft-edge:https://ss64.com

Chrome Shortcuts

If Chrome is not your default browser, but you want to open a web page using Chrome, set the Shortcut Target to a path like the following, note that Chrome installs itself in the x86 folder even though it is a 64 bit application:

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" https://ss64.com

Examples

Create a shortcut to MyApp.exe

 SHORTCUT -f -t C:\demo\MyApp.exe -n %userprofile%"\start menu\programs\MY APP\MY APP"

An alternative is to use VBScript, call the VB script with cscript like so:
CSCRIPT C:\batch\makeshortcut.vbs

Optional sections in the VBscript below are commented out:

   strLinkFile = "$env:Public\Desktop\MyShortcut.lnk"
   strTargetPath = "C:\demo\MyApp.exe"
   Set objWS = WScript.CreateObject("WScript.Shell")
   Set objLink = objWS.CreateShortcut(strLinkFile)
   
   objLink.TargetPath = $strTargetPath
   '  objLink.Arguments = ""
   '  objLink.Description = "MyProgram"
   '  objLink.HotKey = "ALT+CTRL+F"
   '  objLink.IconLocation = "%SystemRoot%\SystemResources\shell32.dll.mun, 94"
   '  objLink.WindowStyle = "1"
   '  objLink.WorkingDirectory = "C:\Program Files\MyApp"
   objLink.Save

The same thing can be done to create a shortcut in PowerShell:

   $strTargetPath = "C:\demo\MyApp.exe"
   $strLinkFile = "$env:Public\Desktop\MyShortcut.lnk"
   $WScriptShell = New-Object -ComObject WScript.Shell
   $Shortcut = $WScriptShell.CreateShortcut($strLinkFile)
   $Shortcut.TargetPath = $strTargetPath
   $Shortcut.IconLocation = "%SystemRoot%\SystemResources\shell32.dll.mun, 94"
   $Shortcut.Save()

“The reasonable man adapts himself to the world: the unreasonable one persists in trying to adapt the world to himself. Therefore all progress depends on the unreasonable man” ~ George Bernard Shaw

Related commands:

Explorer.exe - Open Windows Explorer to show a directory, also accepts variables.
MD - Create folder(s)
FSUTIL - Create a Hardlink.
Pin a SHORTCUT to the start Menu (VBScript)
PowerShell: New-Item -ItemType SymbolicLink
RUN commands - Start | Run commands.
Q158682 - Shortcuts resolve to a UNC Path (LinkResolveIgnoreLinkInfo)
Q150215 - Disable Automatic Shortcut Resolution.
Q254493 - Shortcut.exe fails with sub-folder names.
Q263324 - Shortcut.exe truncates long path names.
Q134552 - Shortcut key for shortcut only works when placed on Start Menu.
Equivalent bash command (Linux): symlink - Make a new name for a file, ln - Make links between files.


 
Copyright © 1999-2022 SS64.com
Some rights reserved