Guy’s Scripting Ezine 119 – Shortcuts

Guy’s Scripting Ezine 119 – VBScript Desktop Shortcuts


This Week’s Secret

If the car was the only form of transport that you knew about, then you would miss out flying in a plane or sailing in ship.  So it is with scripting, if you only knew about network objects then you are denying your self a whole area of scripting, for example shell objects.

So that I can troubleshoot scripts, I like to increase my range of CreateObject("WScript.NOUNS").  Take the case, where I cannot get the correct method to work, for example obj.CreateShortcut or obj.SendKeys.  The underlying problem is that before I can use .createShortCut, I must create a shell object and not a network object.  Consequently, this is what I would script: CreateObject("WScript.Shell").  CreateShortcut and indeed SendKeys, are methods available for shell objects, but are not available if you create network objects.

This Week’s Mission

This week’s mission is to create a desktop shortcut.  You may wish to do this if you have a proprietary program that you are rolling out to a group of users.  The idea is to provide a desktop shortcut via a logon script.  What happens is users double click on the shortcut and thus execute their program, which may even be on a remote network share.

Example Script: Create a desktop shortcut


None.  However, after one or two test runs you may wish to change the variables in order to experiment with other descriptions, icons, or programs.


  1. Copy and paste the script below into notepad or get a script editor such as OnScript.
  2. Save the file with .vbs extension e.g. CreateShortcut.vbs
  3. Double click your script and check your desktop for a new icon called WordProcess.

‘ CreateShortCut.vbs – Create a Desktop Shortcut.
‘ VBScript to create .lnk file
‘ Author Guy Thomas
‘ Version 2.4 – July 2006
‘ ———————————————————-‘
Option Explicit
Dim objShell, objDesktop, objLink
Dim strAppPath, strWorkDir, strIconPath

‘ ————————————————–
‘ Here are the variables that to change if you are making a ‘real’ script

strWorkDir ="C:\windows"
strAppPath = "%SystemRoot%\notepad.exe"
strIconPath = "%SystemRoot%\system32\SHELL32.dll,5"

Set objShell = CreateObject("WScript.Shell")
objDesktop = objShell.SpecialFolders("Desktop")
Set objLink = objShell.CreateShortcut(objDesktop & "\WordProcess.lnk")

‘ —————————————————
‘ Section which adds the shortcut’s key properties

objLink.Description = "WordProcess"
objLink.HotKey = "CTRL+SHIFT+X"
objLink.IconLocation = strIconPath
objLink.TargetPath = strAppPath
objLink.WindowStyle = 3
objLink.WorkingDirectory = strWorkDir


‘ End of creating a desktop shortcut

Learning Points

Note 1:  Observe how we create a shell object with Set objShell = CreateObject("WScript.Shell")

Note 2:  Once we have created the shell object then we can manipulate it with methods, for example .CreateShortCut

Note 3:  On its own, the shortcut link is not much use; we need to give it power by adding properties, the most important of which is .TargetPath.

Note 4:  Trace how the variables control the objLink properties.  Employing variables makes it easier to amend the script and thus create shortcuts which launch different applications.

Note 5:  See how the script takes care of the path with: objDesktop = objShell.SpecialFolders("Desktop")

Guy Recommends:  A Free Trial of the Network Performance Monitor (NPM)Review of Orion NPM v11.5 v11.5

SolarWinds’ Orion performance monitor will help you discover what’s happening on your network.  This utility will also guide you through troubleshooting; the dashboard will indicate whether the root cause is a broken link, faulty equipment or resource overload.

What I like best is the way NPM suggests solutions to network problems.  Its also has the ability to monitor the health of individual VMware virtual machines.  If you are interested in troubleshooting, and creating network maps, then I recommend that you try NPM now.

Download a free trial of Solarwinds’ Network Performance Monitor

VBScript Desktop Shortcut Challenges

1) Amend the icon. This is just a cosmetic change in the appearance of the desktop icon. Try replacing 5 with 175 in: strIconPath = "%SystemRoot%\system32\SHELL32.dll,175".  To research the available icons, right-click the icon, select properties, Change Icon and make your choice.  It seems to me that the logic was the first icon is zero, then you count down (row-wise), thus the bottom of the first column is 3, top of the second column 4 and so on.

2) Research your own applications.  If you cannot think of any try WordPad, Paint or even Freecell.  Once you have found another executable, amend the strAppPath.

3) Create a Windows 8 Metro UI Tile

Guy Recommends: Tools4ever’s UMRAUMRA The User Management Resource Administrator

Tired of writing scripts? The User Management Resource Administrator solution by Tools4ever offers an alternative to time-consuming manual processes.

It features 100% auto provisioning, Helpdesk Delegation, Connectors to more than 130 systems/applications, Workflow Management, Self Service and many other benefits. Click on the link for more information onUMRA.

Summary of Creating Shortcuts with VBScript

In order for VBScript to create a desktop shortcut, first create a shell object.  The secret is then to add appropriate values for the application, the description and the icon.  As with so many scripts, these values are best controlled by variables.  One practical use would be to supply a shortcut via a logon script so that users had access to a new network application.

If you like this page then please share it with your friends


Windows Vista Registry Tweaks: