fortypoundhead.com

SHORTCUT

Posted On 2007-04-24 by FortyPoundHead
Keywords:
Tags: Windows Commandline Windows
Views: 2182


Create a windows shortcut (.LNK file)

Syntax

SHORTCUT [options]

Key

Source options:

-t target : The path and file name of the application. -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.

options for the shortcut file to be created

-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 non tracking (Stupid)

Export options

-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)
-l logfile : save any error messages in the specified file. If shortcut.exe fails to create a new shortcut, it does NOT set an errorlevel.

Example

@ECHO off
MD \%userprofile\%"\start menu\programs\MY APP"
SHORTCUT -f -t C:\MyApp.exe -n \%userprofile\%"\start menu\programs\MY APP\MY APP"Alternatively use WSH to create a shortcut:
optional sections in the VBscript below are commented 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

Resolve Shortcut Links

If a shortcut to a file breaks, then by default Windows will attempt to automatically locate the shortcut destination by performing a simple search. To change this default - edit the registry:
HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer
NoResolveTrack=1
(DWORD)
This can also be controlled at Group Policy level in: User Config\Admin Templates\Start Menu & Taskbar.

If a shortcut .LNK file is copied to another machine, then by default the shortcut''s target may be automatically updated - e.g. create a shortcut on Machine1 to C:\AUTOEXEC.BAT when copied to Machine2 the shortcut will point back to \\Machine1\c$\AUTOEXEC.BAT To change this default - add this to the registry before creating the shortcut:
HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer "LinkResolveIgnoreLinkInfo"=dword:00000001

Favorites

Often confused with shortcuts, Internet Explorer Favourite (.URL) files are simple text files which you can create with a few ECHO statements.


About the Author

FortyPoundHead has posted a total of 1974 articles.

 


Comments On This Post

No comments on this post yet!


Do you have a thought relating to this post? You can post your comment here. If you have an unrelated question, you can use the Q&A section to ask it.

Or you can drop a note to the administrators if you're not sure where you should post.


Your IP address is:54.166.188.64

Before you can post, you need to prove you are human. If you log in, this test goes away.




Recent Forum Posts

Advanced search added
dwirch posted on September 23, 2017 at about 13:44 in Site News

Job Spammer: Gaurav Mehta - AgreeYa Solutions
dwirch posted on September 22, 2017 at about 10:35 in Spammers

Job Spammer: Prutha Siri - Javelin Systems
dwirch posted on September 10, 2017 at about 6:15 in Spammers

New security implemented
dwirch posted on September 7, 2017 at about 7:16 in Site News

Malicious IP Checker Companion Tool
dwirch posted on August 12, 2017 at about 20:24 in Site News

Job Spammer: Steve Adams
dwirch posted on August 8, 2017 at about 7:44 in Spammers