Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can I create a shortcut file (.lnk) to another file or executable, using command line utilities?

share|improve this question
There doesn't appear to be any straightforward way to do that. Some people have written tools that let you do it; here's one of them. A Google search for "windows create shortcut command line" turns up some others. (I haven't tried any of them.) –  Keith Thompson Feb 20 '12 at 18:51
@iglvzx - I'm not sure that the editing you did is correct. I don't think that Shantanu needs a batch script - it could be any way of creating a *.lnk to another *.exe file. –  alfasin Feb 20 '12 at 19:53
@alfasin I added (.ink file), as there was some confusion. I revised the question to reflect Shantanu's comment. While you do provide a way to make 'shortcuts', it does not answer this specific question. –  iglvzx Feb 20 '12 at 19:57
@iglvzx understood, thanks! –  alfasin Feb 21 '12 at 1:26
add comment

3 Answers

up vote 15 down vote accepted

There is some very useful information on this site: http://ss64.com/nt/shortcut.html

Seems like there is some shortcut.exe in some resource kit which I don't have.
As many other sites mention, there is no built-in way to do it from a batch file.

But you can do it from a VB script:

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"

So, if you really must do it, then you could make your batch file write the VB script to disk, invoke it and then remove it again. For example, like so:

@echo off
echo Set oWS = WScript.CreateObject("WScript.Shell") > CreateShortcut.vbs
echo sLinkFile = "%HOMEDRIVE%%HOMEPATH%\Desktop\Hello.lnk" >> CreateShortcut.vbs
echo Set oLink = oWS.CreateShortcut(sLinkFile) >> CreateShortcut.vbs
echo oLink.TargetPath = "C:\Windows\notepad.exe" >> CreateShortcut.vbs
echo oLink.Save >> CreateShortcut.vbs
cscript CreateShortcut.vbs
del CreateShortcut.vbs

Running the above script results in a new shortcut on my desktop:
Resulting shortcut

Here's a more complete snippet from an anonymous contributor (updated with a minor fix):

@echo off
SET LinkName=Hello
SET Esc_LinkDest=%%HOMEDRIVE%%%%HOMEPATH%%\Desktop\!LinkName!.lnk
SET Esc_LinkTarget=%%SYSTEMROOT%%\notepad.exe
SET cSctVBS=CreateShortcut.vbs
SET LOG=".\%~N0_runtime.log"
  echo Set oWS = WScript.CreateObject^("WScript.Shell"^) 
  echo sLinkFile = oWS.ExpandEnvironmentStrings^("!Esc_LinkDest!"^)
  echo Set oLink = oWS.CreateShortcut^(sLinkFile^) 
  echo oLink.TargetPath = oWS.ExpandEnvironmentStrings^("!Esc_LinkTarget!"^)
  echo oLink.Save
cscript //nologo .\!cSctVBS!
DEL !cSctVBS! /f /q
)1>>!LOG! 2>>&1
share|improve this answer
Related: MSDN, Shell Links –  iglvzx Feb 20 '12 at 20:11
add comment

After all the discussions we had here, this is my suggested solution: download: http://optimumx.com/download/Shortcut.zip extract it on your desktop (for example). Now, suppose you want to create a shortcut for a file called scrum.pdf (also on desktop):
1. open CMD and go to desktop folder
2. run: Shortcut.exe /f:"%USERPROFILE%\Desktop\sc.lnk" /a:c /t:%USERPROFILE%\Desktop\scrum.pdf

it will create a shortcut called sc.lnk on your desktop that will point to the original file (scrum.pdf)

share|improve this answer
That's not a shortcut; it's just a batch file that invokes a specified program. –  Keith Thompson Feb 20 '12 at 18:47
a shortcut is something you run from windows, since he used CMD in the title and put the tag "command-line" I assumed he wants to run it from CMD. A batch file is the equivalent of a windows "shortcut" when you run in CMD (dos like) env. –  alfasin Feb 20 '12 at 18:51
Since he put "shortcut (.lnk file)" in the body of the question, I assumed he wants to create an actual shortcut. –  Keith Thompson Feb 20 '12 at 18:52
sorry for clarity i wanted to have a icon on my desktop that i made in cmd that would be a shortcut to a exe file –  Shantanu Feb 20 '12 at 19:23
now that I finally understood (slow thinker - what can you do...) I changed my answer. hope it helps! –  alfasin Feb 21 '12 at 1:42
add comment

Besides shortcut.exe, you can also use the command line version of NirCmd to create shortcut. http://nircmd.nirsoft.net/shortcut.html

share|improve this answer
I recomend almost everything from NirSoft, it's the ultimate geek toolset –  That Brazilian Guy Sep 30 '13 at 23:29
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.