How to create a shortcut from the command line

Working on Windows, I install Windows a lot.  This means a lot of my customizations have to be re-applied every time I install.  To save myself some time I created a script which applies some of them. Last time I showed how to set the desktop wallpaper from a command-line app.

This time, a script to create a shortcut.  The example usage creates a shortcut to Notepad and puts that in the "SendTo" folder.  I find this very useful because I often need to edit text files that have non-".txt" assocations.  (There are also other shortcuts I create with it.)


Here's the script:

>type create-shortcut.vbs

If WScript.Arguments.Count < 2 Or WScript.Arguments.Count > 3 Then
    WScript.Echo "Expected two or three arguments; got " & WScript.Arguments.Count
    WScript.Echo "First argument is the file to create"
    WScript.Echo "Second is the command to link to"
    WScript.Echo "Third, if present, is the arguments to pass"
End If

Set shell = WScript.CreateObject("WScript.Shell")

Set link = shell.CreateShortcut(WScript.Arguments(0))
link.TargetPath = WScript.Arguments(1)

If WScript.Arguments.Count = 3 Then
    link.Arguments = WScript.Arguments(2)
End If


>cscript create-shortcut.vbs "%appdata%\Microsoft\Windows\SendTo\Notepad.lnk" notepad.exe

EDIT 2015-10-31: added script to

Comments (2)

  1. So let me get this straight ... the basic shell verbs are shown in English, even though you're obviously using some other language for your UI?

    1. In this screenshot I was using a right-to-left pseudoloc version of Windows, but I had installed a US English version of Office on top of it.

      The verbs that came from Office (Open, New, Print, Show) are in English.

Skip to main content