How to create Shortcuts in Windows from the command line

It seems that there is not a direct way to create a shortcut from the command line in Windows. The solution presented here takes less than two minutes to set up and works pretty good. However, if you find a better one, I would like to know.

First you have to create a small text file by the name mkshortcut.vbs. Use your favorite text editor to edit the file, even notepad will do. Then copy the following text and paste it into the file:

set WshShell = WScript.CreateObject("WScript.Shell" )
set oShellLink = WshShell.CreateShortcut(Wscript.Arguments.Named("shortcut") & ".lnk")
oShellLink.TargetPath = Wscript.Arguments.Named("target")
oShellLink.WindowStyle = 1

Then save the file and exit the editor. Make sure that you move the file in a directory in your PATH (usually C:WINDOWSSystem32 is fine). Now, from the command line you can create shortcuts this way:

mkshortcut /target:TargetName /shortcut:ShortcutName

You will have to replace TargetName with the name of the target file and ShortcutName with the name of the shortcut to be created (do not include a .lnk extension!). For example:

C:>mkshortcut /target:"c:/documents and settings/giannis/desktop" /shortcut:"My Desktop"

C:>dir *.lnk
Volume in drive C has no label.
Volume Serial Number is 70FC-EBB4

Directory of C:

12/03/2008  11:12 AM               453 My Desktop.lnk
1 File(s)            453 bytes
0 Dir(s)  46,659,989,504 bytes free


Make sure that in target you include the full path of the target file name, starting with the drive letter and going down. For some reason Windows seem unable to create shortcuts with a relative path. Always use absolute paths for target.

This entry was posted in Uncategorized. Bookmark the permalink.

39 Responses to How to create Shortcuts in Windows from the command line

  1. Br4dy 5m17h says:

    Just used this on Win7x64 – worked great. Thanks!

  2. Mahindra says:

    Good one. Helped me a lot

  3. KK says:

    Thanks for this tutorial, works great!
    I’m wondering how I can add extra parameters for the shortcut, any ideas?
    What I mean is something like this “C:tempfile.exe -show edited” etc.

    I tried using apostrophes but then it won’t find the file at all!

  4. KK says:

    Got it.
    If you need extra parameters, you’ll have to add
    oShellLink.Arguments = “-params /whatever”
    after the TargetPath. :)

  5. Kyle Clough says:

    How would you set it to open with a program like textpad. Saying its like a config file

  6. Rich says:

    Awesome script – is there any way to add arguments to set a specific icon file?

  7. petcomp says:

    Good Work

  8. Rahul says:

    Awesome, thanks. Am using this in a project.

  9. mircea says:

    how you can specify a location to save the shortcut

    we have target, name of the shortcut but if i want to save on the network drive (example “x:DAYvoice.lnk”)
    we need a new option (example “/save”)
    C:>mkshortcut /target:”c:/documents and settings/giannis/desktop” /shortcut:”My Desktop” /save:”x:DAY”

  10. Mohammad Khodayar says:

    This command maybe help you

    mklink /d %userprofile%desktopdata d:data

    Good Luck

    Iran ahwaz

  11. Sanjay says:

    How can i add this to run on user logon, does the VBS script have to be on the local machine of the users?

  12. Gaurav says:

    Can you please update this script to support generic shortcut creation?
    mkshortcut.vbs /target:”" /shortcut: /location:

  13. Remco says:

    Sweet! I used it succesfully to re-create a shortcut to Excel in my start menu. Doing it straight from the explorer gave me a nasty msvcr80.dll.

    I rewrote the script a little to this:
    set WshShell = WScript.CreateObject(“WScript.Shell” )
    sStartmenuPath = WshShell.SpecialFolders(“StartMenu”)
    set oShellLink = WshShell.CreateShortcut(sStartmenuPath & “” & Wscript.Arguments.Named(“shortcut”) & “.lnk”)
    oShellLink.TargetPath = Wscript.Arguments.Named(“target”)
    oShellLink.WindowStyle = 1

    More info on SpecialFolders is here:

    Thanks for sharing!

  14. Joeordie says:

    Just starting to learn scripting…

    I think i have the basic language down but can some one post what this script would look like if it had a “location to save .lnk” object?

    Im using this in a batch file process to copy files from a network drive then create a shortcut to delete the files when the user is done, need to copy the shortcut to the C:/User/Public/Desktop location.

    Also when i run the mkshortcut.vbs from the command line i get this error:

    Windows Script Host
    Script: C:Windowssystem32mkshortcut.vbs
    Char: 1
    Error: Invalid proceedure call or argument
    Code: 800A0005
    Source: Microsoft VBScript runtime error

    would appreciate any help.

  15. Joeordie says:

    whoops i meant “location to save .lnk” argument!!!!!!

  16. Jitesh says:

    Thanks. Great stuff.

  17. Graham says:

    Thanks for the tip and taking the time to write it :) . Big help

  18. Larry says:

    Thank you !! Enabled automated build of links to template files under %userprofile%.

  19. Kevin says:

    This is great- thanks!

    If you also need to set the “Start in” or “Working Directory” you can add to the script as follows:

    set WshShell = WScript.CreateObject(“WScript.Shell” )
    set oShellLink = WshShell.CreateShortcut(Wscript.Arguments.Named(“shortcut”) & “.lnk”)
    oShellLink.TargetPath = Wscript.Arguments.Named(“target”)
    oShellLink.WorkingDirectory = Wscript.Arguments.Named(“startin”)
    oShellLink.WindowStyle = 1

    Then the command would be:
    mkshortcut /target:”C:\target_directory\file” /startin:”C:\target_directory” /shortcut:”C:\shortcut_directoy\shortcut”

  20. MSM SHAMRAN says:

    Thanks bro.. It works..!!

  21. hope merrill says:

    that didnt work so do u kno an easy way to do it

  22. Herman says:

    Thanks, this really helped me a lot!
    To do this from a batch file I did the following:

    ECHO set WshShell = WScript.CreateObject(“WScript.Shell” ) > “%userprofile%\desktop\shortcut.vbs”
    ECHO set oShellLink = WshShell.CreateShortcut(Wscript.Arguments.Named(“shortcut”) ^& “.lnk”) >> “%userprofile%\desktop\shortcut.vbs”
    ECHO oShellLink.TargetPath = Wscript.Arguments.Named(“target”) >> “%userprofile%\desktop\shortcut.vbs”
    ECHO oShellLink.Arguments = Wscript.Arguments.Named(“Arguments”) >> “%userprofile%\desktop\shortcut.vbs”
    ECHO oShellLink.WindowStyle = 1 >> “%userprofile%\desktop\shortcut.vbs”
    ECHO oShellLink.Save >> “%userprofile%\desktop\shortcut.vbs”

    “%userprofile%\desktop\shortcut.vbs” /target:”C:\Windows\System32\control.exe” /Arguments:”smscfgrc” /shortcut:”Configuration Manager”

    del “%userprofile%\desktop\shortcut.vbs” /S /Q >NUL

  23. Jes Selien says:

    Thanks for the program, however like some others, I had errors like some of the others.
    Since arguements ran from a batch script require to be in quotes, otherwise the value will be cut out, I had to remove quotes first within the .vbs file in order to get the script to create a shortcut without errors. Plus I changed some of the variable names.

    ‘Remove quotes
    myFileName = WScript.Arguments.Named.Item(“filename”)
    myTarget = WScript.Arguments.Named.Item(“target”)
    myStartin = WScript.Arguments.Named.Item(“startin”)
    myFileName = replace(myFileName, “”"”, “”)
    myTarget = replace(myTarget, “”"”, “”)
    myStartin = replace(myStartin, “”"”, “”)

    ‘Create Shortcut
    Set objShell = WScript.CreateObject(“WScript.Shell”)
    Set objLink = objShell.CreateShortcut(myFileName & “.lnk”)
    objLink.TargetPath = myTarget
    objLink.WorkingDirectory = myStartin
    objLink.WindowStyle = “1″

    ‘Clean up
    Set myFileName = Nothing
    Set myTarget = Nothing
    Set myStartin = Nothing
    Set objShell = Nothing

  24. odvahaCZ says:

    Thanks for this ;]

  25. Jaco vd Walt says:


    I would like to create a batch file, to create a RDP link to a specific address on the desktop. A file that i can mail to users to just run.


  26. Melique says:

    this is sweet as hell

  27. Jesse Mcmillan says:

    I need a walkthrough with this

  28. bing says:

    Everything is very open with a precise description of the issues.
    It was definitely informative. Your site is very useful.
    Thank you for sharing!

  29. mike kanakis says:

    I did it, and I get a shortcut with blank name. Which means, that if I do it again, new shortcut will replace old. I tried by changing “.lnk” to “.lnk” (so later I rename it) and what I had was a void file with mkshortcut name. Any solution?

    • mike kanakis says:


      I did it, and I get a shortcut with blank name. Which means, that if I do it again, new shortcut will replace old. I tried by changing “.lnk” to “.lnk” (so later I rename it) and what I had was a void file with mkshortcut name. Any solution?

  30. Dian says:

    giannis, something is compelety wrong . This shortcut not have “start in” not have “target” not have anything important. Not work.

  31. Dave says:

    It donn’t work and I did it all right

  32. David says:

    This has been a great help in setting up programs through SCCM and other manually installed applicaitons

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>