Creating a Shortcut icon using Visual Basic Scripting Language

Visual Basic Scripting language is a 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…

Visual Basic Scripting language is a 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 your Network user My Documents folders so that they can access a new resource or an old folder.

The code below places a Shortcut on the User’s 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 a text file to create multiple shortcuts in multiple folders.  There are plenty of examples on the internet about 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

Similar Posts

  • Adding a Domain Account to a local security group

    Windows Scripting Host is a very powerful tool that allows you to use simple Visual Basic code syntax to change or customise settings of a computer.  This script will allow you to use Window Active Directory Group Policy to add a domain user account or group to a local security group of a Windows 2000/XP…

  • Script to delete files after x days

    Have you ever needed to automate the cleaning of a folder that say is used as part of a backup or just as a dumping ground.  Using this script will help you to speed up the cleaning process by deleting files from any folder or UNC path that are older than the specified (x) days.

  • Getting a list of users that belong to a Windows Security Group

    Some times it is not always easy to see the name that you are looking for in a GUI list of users that Active Directory Users and Computers displays.  Using VB Scripting you can obtain a list of users from a Security group and output this to screen or to text file.

  • Remove all profiles on startup

    Occasionally Windows XP manages to stuff up its roaming profile, when this happens, resolving profile related problems can be difficult.  Schools running Community Connect 3 will benefit from the “Reset Profile” option in the System Management Console, however, profile problems may quickly return, as they often remain on several workstations. To help cure this problem…