Click here to Skip to main content
11,412,526 members (70,950 online)
Click here to Skip to main content

Pin a Shortcut onto the Taskbar or Start Menu

, 8 Oct 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
Pin a shortcut onto the Taskbar or Start Menu using VBScript


This script solves the problem of pinning applications (adding short-cuts) onto the task bar and start menu with no user interaction. This can be especially useful to System Administrators in a domain environment looking to add short-cuts to a profile with no user interaction. I find this solution is best implemented with Group Policy Object's logon script but it can be used independently as well.


The code works by passing parameters to a sub procedure with an application path & name, a name for the future pinned item, and a boolean directing the location of pinned item. The first step creates a short-cut in a temporary location. This is a workaround necessity to create a short-cut for applications that will not be pinned directly. The next step takes that short-cut and loops through its shell object's verbs and selects the pinned item the boolean selected pinned location. Finally, it selects the matched verb and pins the application to the selected pinned location.

Here is the full script in VBScript:

If WScript.Arguments.Count = 3 then
    Call PinApplicationToTaskBar(WScript.Arguments(0), WScript.Arguments(1), WScript.Arguments(2))
    WScript.Echo "Missing parameters.  String AppPathAndName String ShortcutName Boolean OnStartMenu." _
    & vbCr & vbCr & "  Example cmd.exe CMD  false" & vbCr & _
    vbCr & "  Example %windir%\system32\SnippingTool.exe SnipIt false" 
End If
Public Sub PinApplicationToTaskBar(AppPathAndName, ShortcutName, OnStartMenu)
    'This is on for a soft failure. Uncomment this if error checking for a hard failure is needed for debugging.
    On Error Resume Next

    Dim FileSystemObj, ObjShell, ObjShellApp
    Set ObjShell = WScript.CreateObject("WScript.Shell")
    Set FileSystemObj = CreateObject("Scripting.FileSystemObject")
    'Create a temp location for the short-cut to exist
    TempShortcutLocation = FileSystemObj.GetFolder(ObjShell.ExpandEnvironmentStrings("%TEMP%"))
    'Where is it being pinned?  Determine the location where the pinned item will reside
    If(trim(lcase(OnStartMenu)) = "true") then ' pinned to start menu
        HasAlreadyBeenPinnedShortCut = ObjShell.ExpandEnvironmentStrings("%APPDATA%") & _
        "\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu"
        HasAlreadyBeenPinnedShortCut = ObjShell.ExpandEnvironmentStrings("%APPDATA%") & _
        "\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar"
    End If
    'Temporary location for the application short-cut
    TempShortcut = TempShortcutLocation & "\" & ShortcutName & ".lnk"
    'Possible location of a pinned item
    HasAlreadyBeenPinnedShortCut =  HasAlreadyBeenPinnedShortCut & "\" & ShortcutName & ".lnk"
    'If this already exists, than exit this procedure. The application has already been pinned.
    If(FileSystemObj.FileExists(HasAlreadyBeenPinnedShortCut)) Then
        'MsgBox(HasAlreadyBeenPinnedShortCut & " Already Pinned")
        Exit Sub
    End If
    'Create a short-cut using the shell
    Set lnk = ObjShell.CreateShortcut(TempShortcut)
    lnk.TargetPath = AppPathAndName ' Full application path and name
    lnk.Arguments = ""
    lnk.Description = ShortcutName 'The name that appears on the start menu.
    Set ObjShellApp = CreateObject("Shell.Application")
    'Get the newly created short-cut full path
    Set ShortCutToPin =  ObjShellApp.NameSpace(TempShortcutLocation) 
    If(FileSystemObj.FileExists(TempShortcut)) Then 
        Dim ShortCutToPinItem, verb
        'Set the location to pin the item to do based on the passed OnStartMenu argument
        If(trim(lcase(OnStartMenu)) = "true") then
            verbToDo = "Pin to Start Men&u"
            verbToDo = "Pin to Tas&kbar"
        End If
        For Each ShortCutToPinItem in ShortCutToPin.Items()
            'Look for the pinning verb when the temporary short-cut name matches the passed ShortcutName argument
            If (ShortCutToPinItem.Name = ShortcutName) Then
                'Loop through the shell object's (the short-cut) commands looking for the pinning method.
                For Each verb in ShortCutToPinItem.Verbs 
                    'The verb matches the verbToDo so pin it to verb's defined location
                    If (verb.Name = verbToDo) Then verb.DoIt
            End If
        'Delete the temporary short-cut used to pin the application
    End If
    'clean up
    Set ObjShell =  Nothing
    Set FileSystemObj = Nothing
    Set ObjShellApp = Nothing
End Sub

Using the Code

The best way to create a pinned application is by calling the "PinApplicationToTaskBar" procedure.

There are only three arguments that need to be passed to this script:

  1. Full application name and path
  2. Name for the new pinned item
  3. A boolean to pin onto the Start Menu (true) or Taskbar (false)

Using the procedure example:

Call PinApplicationToTaskBar("C:\WINDOWS\system32\SnippingTool.exe", _
"Snipping Tool", "true")

Using the command line:

PinToBar.vbs AppPathAndName ShortcutName OnStartMenu

Pinning the Snipping Tool onto the Taskbar:

C:\PinToBar.vbs C:\WINDOWS\system32\SnippingTool.exe "Snipping Tool" false

Pinning a Command Prompt onto the Start Menu:

C:\PinToBar.vbs C:\WINDOWS\system32\cmd.exe "Command Prompt" true


  1. Programmatically PIN shortcut onto Taskbar on Win 7 by Wayne Ye
  2. Pin and unpin applications from the taskbar and Start-menu by Jan Egil Ring, Crayon
  3. MSDN Shell objects for scripting


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Spencer Kittleson
Software Developer
United States United States
No Biography provided
Follow on   LinkedIn

Comments and Discussions

QuestionDoesn't work on Windows Server 2012 R2? [modified] Pin at 7-Nov-14 20:15
memberhighend@web.de7-Nov-14 20:15 
QuestionWhere to enter the code for desired apps... Pin
Member 11136307 at 7-Oct-14 12:34
memberMember 111363077-Oct-14 12:34 
AnswerRe: Where to enter the code for desired apps... Pin
Spencer Kittleson at 8-Oct-14 5:56
professionalSpencer Kittleson8-Oct-14 5:56 
AnswerRe: Where to enter the code for desired apps... Pin
Spencer Kittleson at 8-Oct-14 7:40
professionalSpencer Kittleson8-Oct-14 7:40 
QuestionUnpin from taskbar Pin
vn.9xpro at 19-Sep-14 4:38
membervn.9xpro19-Sep-14 4:38 
AnswerRe: Unpin from taskbar Pin
Spencer Kittleson at 7-Oct-14 19:52
professionalSpencer Kittleson7-Oct-14 19:52 
QuestionErrors Pin
Member 3017514 at 11-Jun-14 3:22
memberMember 301751411-Jun-14 3:22 
SuggestionRe: Errors Pin
Spencer Kittleson at 11-Jun-14 18:39
professionalSpencer Kittleson11-Jun-14 18:39 
GeneralRe: Errors Pin
Member 10901726 at 23-Jun-14 13:22
memberMember 1090172623-Jun-14 13:22 
GeneralRe: Errors Pin
Spencer Kittleson at 1-Jul-14 14:04
professionalSpencer Kittleson1-Jul-14 14:04 
GeneralMy vote of 5 Pin
Wooters at 22-Jan-14 20:43
memberWooters22-Jan-14 20:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150427.1 | Last Updated 8 Oct 2014
Article Copyright 2014 by Spencer Kittleson
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid