The Deployment Guys

Helping to deploy your world automagically...

Pin Items to the Start Menu or Windows 7 Taskbar via Script

Pin Items to the Start Menu or Windows 7 Taskbar via Script

  • Comments 62
  • Likes

Update 28 April 2009 – This post originally had the sample scripts pinning the executable (calc.exe) directly.  A colleague of mine pointed out that it would be better to pin the Start Menu shortcuts for items instead of directly pinning the executable.  This should be done because shortcuts for Windows Installer applications are special.  Launching applications using their Windows Installer shortcuts can, for example, initiate a repair of the application it if is needed.  So I have changed all the samples to point to shortcuts.  I have also rewritten the attached script as an MDT script and add added a function library that allows the CSIDL (constant special item ID list) values for “special” folders to be used a variables in the item path.

--------------------------------------------------------------------------------------

Many customers wish to pre-configure items that are “pinned” to the Start Menu in their Windows images.  Also, since items can now be pinned to the new Taskbar in Windows 7, customers will want to configure “pinned” items there as well.

There is no direct programmatic interface to add pinned items to either the Start Menu or Windows 7 Taskbar.  This was done deliberately to prevent installation programs from spamming these locations with their icons (http://blogs.msdn.com/oldnewthing/archive/2003/09/03/54760.aspx).  This caused many customers to have to take manual steps in the image build process to configure pinned items.  However, there is an indirect way to automate this by using the Shell Objects for Scripting.

When you right click on an object (e.g. file or folder icon) in Explorer, you are presented with a menu of actions like Open, Copy, Create Shortcut.  These actions are called verbs in Shell speak.  The Shell Objects for Scripting allow you to enumerate and execute these verb.  Here is a small snippet of code showing how to enumerate the verbs for Calculator:

Const CSIDL_COMMON_PROGRAMS = &H17
Const CSIDL_PROGRAMS = &H2
Set objShell = CreateObject("Shell.Application")
Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS)
strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path
Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Accessories")
Set objFolderItem = objFolder.ParseName("Calculator.lnk")
Set colVerbs = objFolderItem.Verbs
For Each objVerb in colVerbs
    Wscript.Echo objVerb
Next

Below is the output of a small command line script that I wrote (ListVerbs.vbs, included in the attachment) to list the verbs of an item like Calculator.

Verbs2

As you can see, the verbs Pin to Tas&kbar and Pin to Start Men&u are available as verbs for Calculator on my Windows 7 machine. (The & in the verb precedes the letter that can be used to select that verb from the menu using the keyboard.)  We can therefore use the Shell Objects for Scripting to programmatically execute these verbs.  Below is a snippet of VBScript showing how to pin Calculator to the Start Menu:

Const CSIDL_COMMON_PROGRAMS = &H17
Const CSIDL_PROGRAMS = &H2
Set objShell = CreateObject("Shell.Application")
Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS)
strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path
Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Accessories")
Set objFolderItem = objFolder.ParseName("Calculator.lnk")
Set colVerbs = objFolderItem.Verbs
For Each objVerb in colVerbs
    If Replace(objVerb.name, "&", "") = "Pin to Start Menu" Then objVerb.DoIt
Next

I’ve included in the attachment for this post a switch-driven MDT script, PinItem.wsf, that can be used to pin items to the Start Menu or Windows 7 Taskbar.  This can be used during image builds and these additions do survive the automated profile copy mechanisms in XP and Vista (haven’t tested Windows 7 yet but it should work).  It can also be used in logon scripts, etc.  Please note that this script was written for US English verbs.  The verbs for each action would have to be changed in the script for use with another language.

For automated deployments, some of these items can also be configured through an answer file on Windows Vista and higher.  Windows 7 provides an unattend.xml setting to configure up to three Taskbar pinned items (see TaskbarLinks in Microsoft-Windows-Shell-Setup in the Automated Installation Kit documentation).  And both Windows Vista and Windows 7 provide an unattend.xml setting to configure up to five “recently opened programs” on the Start Menu (StartPanelLinks in Microsoft-Windows-Shell-Setup).  However, neither provide a way in unattend.xml to pin items to the Start Menu.

Disclaimer: The information on this site is provided "AS IS" with no warranties, confers no rights, and is not supported by the authors or Microsoft Corporation. Use of included script samples are subject to the terms specified in the Terms of Use.

This post was contributed by Michael Murgolo, a Senior Consultant with Microsoft Services - U.S. East Region.

Attachment: PinItem.zip
  • <p>Hi, I'm writing an MP3 player (free, to be released soon) that has no UI, and takes advantage of Win7 taskbar features to handle all user input.</p> <p>For one, I dynamically set the main form icon to the song's album art. This presents a problem because when I pin the program, it uses the application icon from the resource file.</p> <p>So my questions are:</p> <p>1. Can I find out if my application is pinned to the taskbar(are these pinned items stored anywhere)? - My application is single-instance anyway, so it doesn't matter if its run from other places.</p> <p>2. I can execute the vbs you've put up here to pin programs to the taskbar, but what about removing it from the taskbar? I didn't find a verb that does this. - I ask this because I can un-pin the application at startup and pin it back on when I'm closed.</p> <p>Thanks in advance, your responses will be most appreciated!</p> <p>email: ananth _at_ ananthonline.net</p> <p>-Ananth</p>

  • <p>Got it! This for people who stumble across this thread looking for information on (un)pinning item from/to the Windows 7 taskbar using .NET.</p> <p>I've written a blog entry on this with some code to boot at <a rel="nofollow" target="_new" href="http://blog.ananthonline.net/?p=37">http://blog.ananthonline.net/?p=37</a>.</p> <p>Hope it helps!</p>

  • <p>Hi. Cool scripts... but...What about</p> <p>when your &quot;pinn to taskabr&quot; and &quot;Pin to start menu&quot; disappeared accidentaly?</p> <p>How to reverse windows registry settings to get them back as asked on this technet forum</p> <p><a rel="nofollow" target="_new" href="http://social.technet.microsoft.com/Forums/en-US/w7itproui/thread/7c0a568b-b960-4a08-a1d2-cf76021cc570">http://social.technet.microsoft.com/Forums/en-US/w7itproui/thread/7c0a568b-b960-4a08-a1d2-cf76021cc570</a></p> <p>Any ideas?</p>

  • <p>its nice to pin and unpin those icons. </p> <p>Thanks!</p> <p>, but...</p> <p>it would be even cooler if it is possible to re-arrange the items.</p> <p>F.e.: if i pin up the Thunderbird icon to the Taskmenu, it should automatically be ordered next to the Internet Explorer.</p> <p>Is this possible?</p> <p>If it is, how?</p>

  • <p>How do you use the ZTI-SpecialFolderLib.vbs? I suppose, I should modify it in some way before calling it from MDT?</p> <p>Thanks!</p>

  • <p>Michael,</p> <p>ZTI-SpecialFolderLib.vbs is a function library used by PinItem.wsf. &nbsp;It needs to be in the same folder as PinItem.wsf.</p> <p>Michael Murgolo</p>

  • <p>Yes - I figured it out. Thank you!</p>

  • <p>Great script and thanks a lot! &nbsp;This has helped me to get pinned items during an MDT build.</p> <p>I was wondering - has anybody had success in getting this working via OSD deployments in SCCM? &nbsp;I'm using the same script and I have everything I need in the package - however, when I deploy during my build &amp; capture task sequence - I get an error in the SMSTS.LOG</p> <p>&quot;Function-GetSpecialFolder: Cannot determine special folder for CSIDL_PROFILES.&quot; &nbsp;</p> <p>I've got the pinitem.wsf, zti-specialfolderslib.vbs, ztiutility.vbs and listverbs.vbs file in the package.</p> <p>However when I log in as a user, and run pinitem.cmd as the user - it works. &nbsp;It just doesn't work when SCCM is trying to do it.</p> <p>Anybody else have a similar problem?</p>

  • <p>DreamensioN,</p> <p>This script depends on the Explorer shell because it is executing shell verbs. &nbsp;OSD runs as the System account with no shell. &nbsp;This cannot be used during OSD.</p> <p>The CSIDL_PROFILES message is not an error. &nbsp;It is an informational message that means that the special folder value was not found. &nbsp;It may simply not be defined in that version of Windows.</p> <p>You would need to use this script during either the image build or in a logon script after the OS is deployed.</p> <p>Michael Murgolo</p>

  • <p>I am trying to figure out where I would specify what I want to pin to the Start Menu. Any Assistance? I am new to this.</p>

  • <p>Justin,</p> <p>Open PinItem.wsf in a text editor. &nbsp;The usage can be found in the script header.</p> <p>Michael Murgolo</p>

  • <p>Hi,</p> <p>Should ZTIUtility.vbs be included in the zip? I don't seem to have it.</p> <p>I only have:</p> <p>ListVerbs.vbs</p> <p>PinItem.cmd</p> <p>PinItem.vbs</p> <p>ZTI-SpecialFolderLib.vbs</p> <p>Cheers</p>

  • <p>Ah nevermind... :)</p> <p>I found a copy here that works.</p> <p><a rel="nofollow" target="_new" href="http://deploymentlive.com/blog/ZTIUtility.vbs">http://deploymentlive.com/blog/ZTIUtility.vbs</a></p> <p>Cheers</p>

  • <p>Ben,</p> <p>ZTIUtility.vbs in included with MDT. &nbsp;Since it is already part of MDT I did not see the need to redistribute another copy.</p> <p>Michael Murgolo</p>

  • <p>Hello guys, and greetings from Portugal!</p> <p>What about avoiding all users to get WMP and IE on the taskbar?</p> <p>Can anyone help me do this?</p> <p>Best Regards,</p> <p>Diogo Sousa</p>

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment