Home > Commands N-Z > Commands S

SHORTCUT


Description | Syntax | Parameters | Switches | Related | Notes | Examples | Errorlevels | Availability

Create a windows shortcut (.LNK file).

Not installed by default, you will find it on the Windows installation CD. Not found on some OEM/Windows 95 installation CD's.


Syntax

SHORTCUT [-t target] [-a arguments] [-d directory] [-i iconfile] [-x index] [-n name] [-c] [-r] [-f] [-s] [-u [spec]] [-l logfile


Parameters

none.


Switches
-a arguments (NT4)
Source option, the arguments passed when the shortcut is used.
-c (NT4)
Change existing shortcut.
-d directory (NT4)
Source option, the folder to start the application in.
-f (NT4)
Force overwrite of an existing short cut.
-i iconfile (NT4)
Source option, the file the icon is in.
-l logfile (NT4)
Export option, save any error messages in the specified file.
-n name (NT4)
The path and file name (.LNK) of the shortcut file.
-r (NT4)
Resolve broken shortcut.
-s (NT4)
Make shortcut non-tracking (Stupid).
-t target (NT4)
Source option, the path and file name of the application.
-u [spec] (NT4)
Export option, 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).
-x index (NT4)
Source option, the index into the icon file.

Related

MD - Create folder(s).
Equivalent Linux BASH commands:
symlink - Make a new name for a file.
ln - Make links between files.


Notes

If shortcut fails to create a new shortcut, it does NOT set an errorlevel.

An alternative for Internet Explorer users is to create a Favourite (.URL) file. These are simple text files which you can create with ECHO statements.

    [InternetShortcut]
     URL=http://www.microsoft.com/

Another option is to use WSH - save the script below with a .VBS extension. (optional sections in the script below are REMed out).

    Set oWS = WScript.CreateObject("WScript.Shell")
    sLinkFile = "C:\MyShortcut.LNK"
    Set oLink = oWS.CreateShortcut(sLinkFile)
    oLink.TargetPath = "C:\Program Files\MyApp\MyProgram.EXE"
    '    oLink.Arguments = ""
    '    oLink.Description = "MyProgram"
    '    oLink.HotKey = "ALT+CTRL+F"
    '    oLink.IconLocation = "C:\Program Files\MyApp\MyProgram.EXE, 2"
    '    oLink.WindowStyle = "1"
    '    oLink.WorkingDirectory = "C:\Program Files\MyApp"
    oLink.Save

Examples
    @ECHO OFF
    ::
    :: Install.cmd
    ::
    ECHO setting up MY APP
    MD %userprofile%"\start menu\programs\MY APP"
    SHORTCUT -f -t C:\MyApp.exe -n %userprofile%"\start menu\programs\MY APP\MY APP"

Errorlevels

none.


Availability
External
DOS
none
Windows
Win95 Win98 WinME
Windows NT
NT4