Create Windows Shortcuts with a Visual Basic Script

I initially set out to find a way to create Windows file shortcuts using CMD.  I remember an old CLI tool called SHORTCUT.EXE that was in past Windows systems.  It was useful but appears to have been depreciated and no longer native to Windows.

As my search continued it became cleat that a better option would be to use a Visual Basic script.

The VBS code for this is fairly straightforward.  We are creating a WScript shell object and then utilizing the CreateShortcuts method.  It lets us modify a variety of properties before saving everything.  See the following working example:

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"

Copy and paste the code above into a text editor, modify it as needed, and save it as a .VBS file.

The sLinkFile variable is where the shortcut will be created and what it will be named.  Be sure to include the .LNK extension on the end.

NOTE: Only the TargetPath property is required; all other optional properties are commented out in the above example.

The following table details each of the available properties:

Property Details
TargetPath (required) The path to the target file.
Arguments Arguments to be added to the end of the target call.
Description A description of the shortcut.
HotKey A keyboard shortcut (hotkey) to open the file.
IconLocation A file whose icon should be used followed by the icon’s index number (I’ve found 0 is usually what I want).
WindowStyle The window size when the file is launched.  1 = normal window, 3 = maximized window, 7 = minimized window
WorkingDirectory Where the file call will start from (start in).

These are all the same options that are seen when looking at a shortcut’s properties via the GUI:


Remember that Visual Basic scripts can be called from the Windows command line, just use CSCRIPTE.EXE or WSCRIPT.EXE to execute them:

WSCRIPT MyScipt.vbs

Of course there are still other methods to create Windows shortcuts.

Another excellent (and new school) method worth mentioning is to use Windows PowerShell, although I won’t dive into that solution in this post.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: