Creating a Shortcut icon using Visual Basic Scripting Language

Visual Basic Scripting language is a very powerful tool for automating many of the day to day jobs that System Administrators are faced with.  Once such task is to create Shortcut icons to applications or to network folders.

Creating Shortcut icons is quite a simple task for VBS and is only limited by your imagination.

You might want to create icons in all of your Network user My Documents folders so that they can access a new resource or perhaps an old folder.

The code below places a Shortcut on the Users desktop that will cause Windows Explorer to open and Explorer Window at named target, in this case D:Users

Copy the code example into Notepad and save as "NewShortcut.vbs"  it is important to make sure that you set the file type to All, otherwise you will end up with a file called "NewShortCut.vbs.txt" that you will have to rename.

To run the code, double click it from an Explorer Window.

This code could be modified so that it reads through a text file to create multiple shortcuts in multiple folders.  See www.microsoft.com/scripting and cwashington.netreach.net for further information and examples of VB Scripting. 

Dim WSHShell
Set WSHShell = WScript.CreateObject("WScript.Shell")

Dim MyShortcut, MyDesktop, DesktopPath

'Read desktop path using WshSpecialFolders object
ShortCutPath = WSHShell.SpecialFolders("Desktop")

'Shortcut Target - ie where is this going to.
ShortCutTarget = "D:USERS"

' Shortcut Name
ShortCutName = "Shortcut to " & ShortCutTarget

' Create a shortcut object on the desktop
Set MyShortcut = WSHShell.CreateShortcut(ShortCutPath & "" & ShortCutName)

'Set shortcut object properties and save it
MyShortcut.TargetPath = ShortCutTarget
MyShortcut.WorkingDirectory = ShortCutTarget
MyShortcut.WindowStyle = 4
MyShortcut.Save
Posted in Scripting.