[[windows_wiki:vbscript_-_create_shortcut]]

VBScript - Create Shortcut

General Information

A vbscript template to create a shortcut.

Checklist

  • OS: Windows XP/7

file create_shortcut.vbs
'==========================================================================
' VBScript:  AUTHOR: Bill Howe 11/15/2011
' NAME: <CreateShortCut.vbs>
' DESCRIPTION: Uses wscript.shell to create a shortcut. 
'==========================================================================
 
'Declare Variables for later use
Option Explicit
Dim Shell, FileSys 'instance of the Shell, FileSystem object
Dim ShortCut 'used to set properties of the shortcut. Comes from using createShortCut
Dim LinkTarget 'Path to executable
Dim LinkArgs 'Arguments sent to executable
Dim LinkLocation 'Place to put shortcut
Dim LinkName 'Name of shortcut
Dim LinkDescription 'Description of shortcut (shows up on mouse hover)
Dim LinkIcon 'Location of the shortcut icon
set Shell = CreateObject("WScript.Shell") 'Create Shell Object
set FileSys = CreateObject("Scripting.FileSystemObject") 'Create FileSystem Object
 
'++++++++++++++++++++++++ EDIT THESE VARIABLES +++++++++++++++++++++++++++++
'-- Enter Full Path to Executable for shortcut to reference --
LinkTarget = "C:\Program Files (x86)\Program.exe"
 
'-- Enter Shortcut arguments --
LinkArgs = ""
 
'-- Enter Location to put shortcut --
LinkLocation = Shell.SpecialFolders("Desktop")
'(or: full path to location, "C:\Users\Robert\Desktop")
 
'-- Enter Name for Shortcut (must begin with \ and end in .lnk) --
LinkName = "\ShortcutName.lnk"
 
'-- Enter Shortcut Description --
LinkDescription = "Shortcut Description Here"
 
'-- Enter Shortcut Icon --
LinkIcon = LinkTarget
'(or: "%SystemRoot%\system32\SHELL32.dll,x" where x is the icon number)
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
'If shortcut already exists, quit and don't create it
If FileSys.FileExists(LinkLocation & LinkName) Then
  Wscript.Quit
End If
 
'Create ShortCut
set ShortCut = Shell.CreateShortcut(LinkLocation & LinkName)
 
'Set Shortcut Properties
ShortCut.TargetPath = LinkTarget 
ShortCut.Arguments = LinkArgs
ShortCut.IconLocation = LinkIcon
ShortCut.description = LinkDescription
ShortCut.Save
  • windows_wiki/vbscript_-_create_shortcut.txt
  • Last modified: 2019/05/26 03:50
  • (external edit)