Pin Items to the Start Menu or Windows 7 Taskbar via Script
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 (https://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.
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.
Comments
Anonymous
January 01, 2003
OK... I thought this script was exactly what I wanted. But I'm confused Michael. You modified this script to run in MDT, yet in the comments you say it can't be run during OSD. So, am I right in hearing that you can run this during an MDT Build and Capture TS, when the host OS has booted and is just about ready to capture, but I can NOT run this script if I want to apply that captured image to a machine during a standard client MDT OSD sequence?Anonymous
January 01, 2003
The comment has been removedAnonymous
January 01, 2003
We have used this during our automated deployment, however the shortcuts are being overwritten when we do a user migration with USMT 4 is there any way of preventing the migration of these items? RegardsAnonymous
January 01, 2003
Must this script be run each time the user logs in, say, within a logon script?? Or only once?? Thank you...Anonymous
January 01, 2003
Justin, Open PinItem.wsf in a text editor. The usage can be found in the script header. Michael MurgoloAnonymous
January 01, 2003
Pete, Yes, I should have plainly stated the requirement that the script depends on ZTIUtility.vbs. However, I will not redistribute files from other Microsoft products/downloads. Those items have an End User License Agreement that must be accepted before using them. However, I have added the stand-alone PinItem.vbs script back to the Zip download. This will be easier to use outside of MDT since it has no external dependencies. Michael MurgoloAnonymous
January 01, 2003
Diogo You would have to use the TaskbarLinks setting mentioned above in unattend.xml to configure the desired initial taskbar links. Michael MurgoloAnonymous
January 01, 2003
A much simpler and free tool is now available called Taskbar Pinner: winaero.com/comment.php to pin anything.Anonymous
January 01, 2003
Ian, I don't believe you can use the technique from my script to use a verb on the "extended" context menu. The Shell Scripting Objects have not been updated to support those. Michael MurgoloAnonymous
January 01, 2003
Philip Colmer, Please check your shortcut file name. On my machine the .lnk file has the name "Microsoft Outlook 2010" not "Outlook 2010". Michael MurgoloAnonymous
January 01, 2003
Hi, When using this script, every now and then I get a Microsoft Visual C++ Runtime library on cscript.exe (the pinitems.vbs executes at user logon - not logon script - different section in GPO). and the error is R6016 not enough space for threaded data. running on windows server 2008 R2 / Citrix 6.5 server, fully patches, Visual C++ 2005, 2008, 2010 both 32 and 64 bit installed. Thanks.Anonymous
January 01, 2003
MrShannon, There is really no way to pin an item for all users after the OS is deployed. This would have to be done in something like a logon script. Michael MurgoloAnonymous
January 01, 2003
tlyczko2, the script should only have to be run once to pin the items. Whether it is visible as a logon script depends on how it is launched. The default script host is wscript.exe, so they should only see dialogs from calls like Wscript.Echo. There may still be some of those that I was using for debugging still in the VBS version. You may need to comment those out to make it completely silent. os7, I have not tried to pin a folder. I don't see an Pin actions on the context menu for folder so I doubt it can be done. Michael MurgoloAnonymous
January 01, 2003
Thomas, I just tested them again on my machine (US English) and they worked fine. As I mentioned in the main blog text, these scripts were written for US English verbs. The verbs for each action would have to be changed in the scripts for use with another language. Michael MurgoloAnonymous
January 01, 2003
I'm trying to use this to pin Outlook to the taskbar after Office has been installed. I'm using this command: cscript.exe %SCRIPTROOT%PinItem.wsf /item:"%CSIDL_COMMON_PROGRAMS%Microsoft OfficeOutlook 2010.lnk" /taskbar but it isn't working. If I run this command from within the MDT environment, I get this output: Property item is now = %CSIDL_COMMON_PROGRAMS%Microsoft OfficeOutlook 2010.lnk Property taskbar is now = Microsoft Deployment Toolkit version: 5.1.1642.01 ------------ Initialization pinitem ------------- The /item switch specified with value: %CSIDL_COMMON_PROGRAMS%Microsoft Office Outlook 2010.lnk The /taskbar switch was specified. Function-GetSpecialFolder: Cannot determine special folder for CSIDL_PROFILES Item "C:ProgramDataMicrosoftWindowsStart MenuProgramsMicrosoft OfficeOutl ook 2010.lnk" does not exist. Exiting Script. ------------ Departing pinitem ------------- ZTI ERROR - Non-zero return code by pinitem, rc = 1 I've checked that the path is correct and that the link file IS there, so I'm at a bit of a loss as to what I can do to get this working. Thanks.Anonymous
January 01, 2003
Michael, ZTI-SpecialFolderLib.vbs is a function library used by PinItem.wsf. It needs to be in the same folder as PinItem.wsf. Michael MurgoloAnonymous
January 01, 2003
DreamensioN, This script depends on the Explorer shell because it is executing shell verbs. OSD runs as the System account with no shell. This cannot be used during OSD. The CSIDL_PROFILES message is not an error. It is an informational message that means that the special folder value was not found. It may simply not be defined in that version of Windows. You would need to use this script during either the image build or in a logon script after the OS is deployed. Michael MurgoloAnonymous
January 01, 2003
The comment has been removedAnonymous
January 01, 2003
Ben, ZTIUtility.vbs in included with MDT. Since it is already part of MDT I did not see the need to redistribute another copy. Michael MurgoloAnonymous
January 01, 2003
Hi @ The Deployment Guys ^^ What do i have to change in the script or have to do, to be capaple of Pinning LNK-Files that are stored on a UNC-Path to the Taskbar or to the Starmenu? When i pinn Shorcuts that are stored on the Local Machine it works fine :). But when i want to Pinn Shorcuts from an a UNC-Path it happens nothing. I don't even get a failiure message >> " Item pinned: True " I dont now what im doing wrong, ist that below the correct way of giving the command to the CMD-Promt?? >> cscript.exe pinitem.vbs /item:"\serverlnkpdfcreator.lnk" /taskbar << >> cscript.exe pinitem.vbs /item:\serverlnkpdfcreator.lnk /taskbar << Thanks in advance!!Anonymous
January 01, 2003
If this script is used within a logon script, does the user see the script running??Anonymous
May 13, 2009
The comment has been removedAnonymous
July 08, 2009
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. I've written a blog entry on this with some code to boot at http://blog.ananthonline.net/?p=37. Hope it helps!Anonymous
October 28, 2009
Hi. Cool scripts... but...What about when your "pinn to taskabr" and "Pin to start menu" disappeared accidentaly? How to reverse windows registry settings to get them back as asked on this technet forum http://social.technet.microsoft.com/Forums/en-US/w7itproui/thread/7c0a568b-b960-4a08-a1d2-cf76021cc570 Any ideas?Anonymous
November 12, 2009
its nice to pin and unpin those icons. Thanks! , but... it would be even cooler if it is possible to re-arrange the items. F.e.: if i pin up the Thunderbird icon to the Taskmenu, it should automatically be ordered next to the Internet Explorer. Is this possible? If it is, how?Anonymous
December 02, 2009
How do you use the ZTI-SpecialFolderLib.vbs? I suppose, I should modify it in some way before calling it from MDT? Thanks!Anonymous
December 06, 2009
Yes - I figured it out. Thank you!Anonymous
December 15, 2009
Great script and thanks a lot! This has helped me to get pinned items during an MDT build. I was wondering - has anybody had success in getting this working via OSD deployments in SCCM? I'm using the same script and I have everything I need in the package - however, when I deploy during my build & capture task sequence - I get an error in the SMSTS.LOG "Function-GetSpecialFolder: Cannot determine special folder for CSIDL_PROFILES." I've got the pinitem.wsf, zti-specialfolderslib.vbs, ztiutility.vbs and listverbs.vbs file in the package. However when I log in as a user, and run pinitem.cmd as the user - it works. It just doesn't work when SCCM is trying to do it. Anybody else have a similar problem?Anonymous
January 08, 2010
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.Anonymous
January 24, 2010
Hi, Should ZTIUtility.vbs be included in the zip? I don't seem to have it. I only have: ListVerbs.vbs PinItem.cmd PinItem.vbs ZTI-SpecialFolderLib.vbs CheersAnonymous
January 24, 2010
Ah nevermind... :) I found a copy here that works. http://deploymentlive.com/blog/ZTIUtility.vbs CheersAnonymous
February 28, 2010
Hello guys, and greetings from Portugal! What about avoiding all users to get WMP and IE on the taskbar? Can anyone help me do this? Best Regards, Diogo SousaAnonymous
March 04, 2010
I would include the ZTIUtility.vbs in your zip download as other people have different uses for this than yours. I for one thought it didn't work until I found the additional file in a link later on. I wanted to use the script as I have a mandatory profile at work meaning my settings changes don't save on log off. With this I can pin my commonly used programs on startup.Anonymous
March 11, 2010
Hello, thanks for the Scripts. But i can't get it to work. I'm using Windows 7 Pro (german) The PinItem.cmd creates a Pinned "Calc" in the Start-Menu, perfect. But in the Taskbar there will be no Calc pinned :-( The PinItem.vbs doesn't work. Neither in the StartMenu, nor in the Taskbar cscript PinItem.vbs /item:c:tempcalc.lnk or cscript PinItem.vbs /item:%windir%system32calc.exe what am I doing wrong?Anonymous
March 18, 2010
The comment has been removedAnonymous
March 23, 2010
The comment has been removedAnonymous
July 19, 2010
I am interested in using this in a Task Sequence that I use to deploy Office 2010. I have been able to use the script on my computer to see that it is in fact pinning, but when I run the script in the task sequence I do not see them appearing in any user account that logs on to the computer. I assume it is because the act of pinning has an effect on the current user profile in the context that the script is running in. So I am wondering how do I apply this against the default user profile? Can I?Anonymous
August 20, 2010
This program is working fine for pinning programs but how would I need to modify it to pin a folder. I have seen and applied the regestry change that allows for the pinning of folders by holding down SHIFT key and right clicking then choosing Pin to Start Menu. I guess the main question is what modifications need to be made to the script to access this Alternative Command verbs list?Anonymous
November 22, 2010
Is there a way to use a verb that only appears on the 'extended' context menu, ie, the context menu that appears when holding down shift+right-click? thanks!Anonymous
February 08, 2011
Hi Michae, Great script - very useful. Is it possible to unpin items again with your script? And how would that be done? CheersAnonymous
March 12, 2011
Also, remember that these options are MUI aware, so if you use them on a TS remember to add settings for each language...Anonymous
March 15, 2011
I revised original script to support a parameter to unpin an item as well, if anyone is interested (same caveat applies: only supports US English, but is easily modified to support other languages). Usage: If you Cheers!
- anthonyx26 '************************************** '* pinitem.vbs ************************ '************************************** ' Windows Script Host Sample Script ' ' ------------------------------------------------------------------------ ' Copyright (C) 2009 Microsoft Corporation ' ' You have a royalty-free right to use, modify, reproduce and distribute ' the Sample Application Files (and/or any modified version) in any way ' you find useful, provided that you agree that Microsoft and the author ' have no warranty, obligations or liability for any Sample Application Files. ' ------------------------------------------------------------------------ '******************************************************************** '* '* File: PinItem.vbs '* Date: 03/04/2009 '* Version: 1.0.2 '* '* Main Function: VBScipt to pin an item to the Start Menu or Taskbar '* '* Usage: cscript PinItem.vbs /item:<path to exe> '* [/taskbar] [/?] '* [/unpin] '* '* Copyright (C) 2009 Microsoft Corporation '* '* Revisions: '* '* 1.0.0 - 04/03/2008 - Created. '* 1.0.1 - 03/02/2009 - Used Replace in PinItem function to remove "&" '* from verb. '* 1.0.2 - 03/04/2009 - Script name was PinToStartMenu.vbs. Added '* /taskbar switch to pin items to taskbar on '* Win7. '* 1.0.3 - 03/15/2011 - Added /unpin switch to pinitem.vbs script to permit '* unpinning items as well '* '******************************************************************** '***************************************************************************** '* Declare Variables '***************************************************************************** Option Explicit 'On Error Resume Next Dim blnPinned Dim blnTaskbar Dim blnUnpin Dim i Dim intOpMode Dim objWshShell Dim objFSO Dim objShell Dim strPath Dim strArguments Dim strOptionsMessage ' Define constants Const CONST_ERROR = 0 Const CONST_WSCRIPT = 1 Const CONST_CSCRIPT = 2 Const CONST_SHOW_USAGE = 3 Const CONST_PROCEED = 4 Const CONST_STRING_NOT_FOUND = -1 Const CONST_FOR_READING = 1 Const CONST_FOR_WRITING = 2 Const CONST_FOR_APPENDING = 8 Const CONST_Success = 0 Const CONST_Failure = 1 Const TRISTATE_USE_DEFAULT = -2 Const TRISTATE_TRUE = -1 'Open the file as Unicode. Const TRISTATE_FALSE = 0 'Open the file as ASCII. blnTaskbar = False blnUnpin = False '***************************************************************************** '* Create Objects '***************************************************************************** Set objWshShell = CreateObject("Wscript.Shell") Set objFSO = CreateObject("Scripting.FileSystemObject") Set objShell = CreateObject("Shell.Application") '******************************************************************** '* Check script host exe and parse command line '******************************************************************** 'Get the command line arguments For i = 0 to Wscript.arguments.count - 1 ReDim Preserve arrArguments(i) arrArguments(i) = Wscript.arguments.item(i) Next 'Check whether the script is run using CScript Select Case intChkProgram() Case CONST_CSCRIPT 'Do Nothing Case CONST_WSCRIPT WScript.Echo "Please run this script using CScript." & vbCRLF & _ "This can be achieved by" & vbCRLF & _ "1. Using ""CScript MODIFYUSERS.vbs arguments"" for Windows 95/98 or" & VbCrLf & _ "2. Changing the default Windows Scripting Host setting to CScript" & vbCRLF & _ " using ""CScript //H:CScript //S"" and running the script using" & vbCRLF & _ " ""MODIFYUSERS.vbs arguments"" for Windows NT." WScript.Quit Case Else WScript.Quit End Select 'Parse the command line Err.Clear() intOpMode = intParseCmdLine(arrArguments, strPath, blnTaskbar, blnUnpin, strOptionsMessage) If Err.Number Then Wscript.Echo "Error 0X" & CStr(Hex(Err.Number)) & " occurred in parsing the command line." If Err.Description <> "" Then Wscript.Echo "Error description: " & Err.Description & "." End If 'WScript.quit End If Select Case intOpMode Case CONST_SHOW_USAGE Call ShowUsage() WScript.quit Case CONST_PROCEED 'Do nothing. Case CONST_ERROR WScript.quit Case Else Wscript.Echo "Error occurred in passing parameters." End Select '******************************************************************** '* Main Script '******************************************************************** WScript.Echo strOptionsMessage blnPinned = PinItem(strPath, blnTaskbar, blnUnpin) If blnUnpin Then WScript.Echo "Item unpinned: " & CStr(blnPinned) Else WScript.Echo "Item pinned: " & CStr(blnPinned) End If If blnPinned Then WScript.Quit(0) Else WScript.Quit(1) End If '******************************************************************** '* '* Function intChkProgram() '* '* Purpose: Determines which program is used to run this script. '* '* Input: None '* '* Returns: intChkProgram is set to one of CONST_ERROR, CONST_WSCRIPT, '* and CONST_CSCRIPT. '* '******************************************************************** Private Function intChkProgram() ON ERROR RESUME NEXT Dim i Dim j Dim strFullName Dim strCommand 'strFullName should be something like C:WINDOWSCOMMANDCSCRIPT.EXE strFullName = WScript.FullName If Err.Number then Wscript.Echo "Error 0x" & CStr(Hex(Err.Number)) & " occurred." If Err.Description <> "" Then Wscript.Echo "Error description: " & Err.Description & "." End If intChkProgram = CONST_ERROR Exit Function End If i = InStr(1, strFullName, ".exe", 1) If i = 0 Then intChkProgram = CONST_ERROR Exit Function Else j = InStrRev(strFullName, "", i, 1) If j = 0 Then intChkProgram = CONST_ERROR Exit Function Else strCommand = Mid(strFullName, j+1, i-j-1) Select Case LCase(strCommand) Case "cscript" intChkProgram = CONST_CSCRIPT Case "wscript" intChkProgram = CONST_WSCRIPT Case Else 'should never happen Wscript.Echo "An unexpected program is used to run this script." Wscript.Echo "Only CScript.Exe or WScript.Exe can be used to run this script." intChkProgram = CONST_ERROR End Select End If End If End Function '******************************************************************** '* '* Function intParseCmdLine() '* '* Purpose: Parses the command line. '* '* Input: arrArguments An array containing input from the command line '* '* Input: strPath Path of exe to pin '* strOptionsMessage String containing options selected '* '* Returns: intParseCmdLine is set to one of CONST_ERROR, CONST_SHOW_USAGE, '* and CONST_PROCEED. '* '******************************************************************** Private Function intParseCmdLine(arrArguments, strPath, blnTaskbar, blnUnpin, strOptionsMessage) ON ERROR RESUME NEXT Dim i Dim strFlag Dim strSwitchValue strFlag = arrArguments(0) Err.Clear() 'Help is needed If (strFlag = "") OR (strFlag="help") OR (strFlag="/h") OR (strFlag="h") OR (strFlag="-h") _ OR (strFlag = "?") OR (strFlag = "/?") OR (strFlag = "?") OR (strFlag="h") Then intParseCmdLine = CONST_SHOW_USAGE Exit Function End If strOptionsMessage = strOptionsMessage & "" & VbCrLf strOptionsMessage = strOptionsMessage & WScript.ScriptName & VbCrLf strOptionsMessage = strOptionsMessage & "" & VbCrLf strOptionsMessage = strOptionsMessage & "Command Line Options:" & vbCrLf strOptionsMessage = strOptionsMessage & "=======================================" & VbCrLf For i = 0 to UBound(arrArguments) strFlag = Left(arrArguments(i), InStr(1, arrArguments(i), ":")-1) If Err.Number Then 'An error occurs if there is no : in the string Err.Clear Select Case LCase(arrArguments(i)) Case "/q" blnQuiet = True strOptionsMessage = strOptionsMessage & "Supress Console Output: " & blnQuiet & VbCrLf Case "/taskbar" blnTaskbar = True strOptionsMessage = strOptionsMessage & "Pin to Taskbar instead of Start Menu: " & blnTaskbar & VbCrLf Case "/unpin" blnUnpin = True strOptionsMessage = strOptionsMessage & "Unpin instead of Pin: " & blnUnpin & VbCrLf Case Else Wscript.Echo arrArguments(i) & " is not recognized as a valid input." intParseCmdLine = CONST_ERROR Exit Function End Select Else strSwitchValue = Right(arrArguments(i), Len(arrArguments(i))-(Len(strFlag)+1)) Select Case LCase(strFlag) Case "/item" strPath = strSwitchValue strOptionsMessage = strOptionsMessage & "Item to pin to Start Menu or Taskbar: " & strPath & VbCrLf Case else Wscript.Echo "Invalid flag " & strFlag & "." Wscript.Echo "Please check the input and try again." intParseCmdLine = CONST_ERROR Exit Function End Select End If Next If (strPath = "") Then Wscript.Echo "The /item switch is required" Wscript.Echo "Please check the input and try again." intParseCmdLine = CONST_ERROR Exit Function End If intParseCmdLine = CONST_PROCEED End Function '******************************************************************** '* '* Function PinItem() '* '* Purpose: Pin item to the Start Menu. '* '* Input: strlPath Path of exe to pin '* blnTaskbar Pin item to Taskbar instead of Start Menu if true '* '* Dependencies: objShell Shell.Application object '* objFSO File System object '* '* Returns: True if the shortcut is created, else false '* '******************************************************************** Function PinItem(strlPath, blnTaskbar, blnUnpin) On Error Resume Next Dim colVerbs Dim itemverb Dim objFolder Dim objFolderItem Dim strFolder Dim strFile If objFSO.FileExists(strlPath) Then '***** Do nothing, folder exists Else '***** Folder does not exist PinItem = False WScript.Echo "File to pin does not exist." WScript.Echo "Please check the input and try again." Exit Function End If strFolder = objFSO.GetParentFolderName(strlPath) strFile = objFSO.GetFileName(strlPath) WScript.Echo "Folder: " & strFolder WScript.Echo "File: " & strFile Err.Clear Set objFolder = objShell.Namespace(strFolder) Set objFolderItem = objFolder.ParseName(strFile) ' ***** InvokeVerb for this does not work on Vista/WS2008 'objFolderItem.InvokeVerb("P&in to Start Menu") ' ***** This code works on Vista/WS2008 Set colVerbs = objFolderItem.Verbs If blnTaskbar Then If blnUnpin Then For each itemverb in objFolderItem.verbs If Replace(itemverb.name, "&", "") = "Unpin from Taskbar" Then itemverb.DoIt Next Else For each itemverb in objFolderItem.verbs If Replace(itemverb.name, "&", "") = "Pin to Taskbar" Then itemverb.DoIt Next End If Else If blnUnpin Then For each itemverb in objFolderItem.verbs If Replace(itemverb.name, "&", "") = "Unpin from Start Menu" Then itemverb.DoIt Next Else For each itemverb in objFolderItem.verbs If Replace(itemverb.name, "&", "") = "Pin to Start Menu" Then itemverb.DoIt Next End If End If If Err.Number = 0 Then PinItem = True Else PinItem = False End If End Function '******************************************************************** '* '* Sub ShowUsage() '* '* Purpose: Shows the correct usage to the user. '* '* Input: None '*</
Anonymous
March 17, 2011
The comment has been removedAnonymous
April 21, 2011
The comment has been removedAnonymous
May 02, 2011
Hello there. The script works fine. Thanks for posting it. But I´ve got a question. Does anybody know how to pin a program with arguments / parameters (like -e) to the taskbar? I dunno how to do that. Cheers :- )Anonymous
May 02, 2011
By the way: The script actually looks like this:
on error resume next Set objShell = CreateObject("Shell.Application") Set objFSO = CreateObject("Scripting.FileSystemObject") set ArgObj = wscript.Arguments dim PfadEXE dim PinModus dim Sprache dim DebugMode Debugmode = 1 PfadEXE = argobj(0) PinModus = argobj(1) Sprache = argobj(2) if DebugMode = 1 then msgbox "-" & PfadEXE & "- -" & PinModus & "- -" & Sprache & "-" end if strlPath = PfadEXE strFolder = objFSO.GetParentFolderName(strlPath) strFile = objFSO.GetFileName(strlPath) Set objFolder = objShell.Namespace(strFolder) set objFolderItem = objFolder.ParseName(strFile) Set colVerbs = objFolderItem.Verbs For each itemverb in objFolderItem.verbs 'Deutsches Pinen if Sprache = 1 Then 'pinen if PinModus = 1 Then If Replace(itemverb.name, "&", "") = "An Taskleiste anheften" Then itemverb.DoIt end if 'unpinen if PinModus = 0 Then If Replace(itemverb.name, "&", "") = "Von Taskleiste lösen" Then itemverb.DoIt end if End if 'Englisches Pinen if Sprache = 0 then 'Pinen if PinModus = 1 then If Replace(itemverb.name, "&", "") = "Pin to taskbar" Then itemverb.DoIt End if 'unpinen if PinModus = 0 then If Replace(itemverb.name, "&", "") = "Unpin this program from taskbar" Then itemverb.DoIt End if end if next
What do I have to add so I can give parameters / arguments? Thanks a lot in advance.
Anonymous
May 10, 2011
Hi, Thank you for your code. But if my default environment is Japanese, "Pin to Start Menu" seems not to work. Do you have any idea?Anonymous
May 10, 2011
I tried the script, it works. Since "Pin to Start Menu" is not using in all language. Would you please tell me how to use this script in other language? Should I provide a script for a language?Anonymous
June 28, 2011
Is there a way to manage the taskbar during OS Deployment via SCCM? I see in the above comments that this solution doesn't work during SCCM OSD Deployment. The issue I'm having is that after deployment the Internet Explorer icon on the TaskBar is defaulting to launching the 64-bit version of IE and I need to change this to launch the 32-Bit version instead. I can't deploy to 1000 desktops and have this icon default to x64 IE. How can I do this during the image process? Preferably in my Build and Capture sequence.Anonymous
July 27, 2011
At what point on my MDT task sequence do I have to add PinItem.wsf script commands? Do I have to run PinItem.wsf before syspreping & capturing? Or do I have to run PinItem.wsf on the actual deployment task sequence?Anonymous
August 02, 2011
great post. Is there a way to Pin a folder that has the menu option on the right, basically the pinned folder would have an right arrow on the right of the name to select the submenus or programs. thanksAnonymous
September 20, 2011
Michael is there a way to pin a shorcut to a folder but as a menu instead of a link? I want to pin it in the start and taskbar menu that has a right arrow to select the advertised programs instead of opening the folder. thanksAnonymous
November 09, 2011
Pinning IE9 to teh taskbar works. But if I start IE9 from startmenu the pinned taskbar icon isn't used. There comes another IE icon right of the pinned one. Does someone know why?Anonymous
September 23, 2012
on windows 8 this works for the taskbar, but not the start screen...Anonymous
November 30, 2012
This was just what I was looking for.......Thanks!Anonymous
February 05, 2013
Hello, is there also a script available for windows 8/server 2012? ThxAnonymous
March 04, 2013
anyone able to get this script to work with .lnk-files that include "em dashes"? thanks a lot!Anonymous
November 11, 2013
Hi Michael, Thanks for the cool script. I am trying to use your script to place icons of programs and files on User start menu. This user account is locked down, with right click context menu and explorer options removed via GPO. So using a script to deploy desired items in the user start menu is the best option. So far, placing icons of programs works just great. How do I use your script to place a shortcut to another script or folder on the Start Menu? Is there a different CSIDL for non executable files and folders? This is what I have so far: 'Declare variables Dim strBBElectronicsIcon, strCalculatorIcon, strNotepadIcon, objFolder, objFolderItem, colVerbs, objShell, strFTPCleanup 'Declare constants Const CSIDL_COMMON_PROGRAMS = &H17 Const CSIDL_PROGRAMS = &H2 'Initialize variables strBBElectronicsIcon = "USB Server.exe" strFTPCleanup = "Cleanup FTP.vbs" 'strCalculatorIcon = "Calculator.lnk" 'strNotepadIcon = "notepad.exe" 'Pin to Start Menu - B&B Set objShell = CreateObject("Shell.Application") Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_PROGRAMS) strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path Set objFolder = objShell.Namespace("C:Program FilesB&B ElectronicsUSB Server 2") Set objFolderItem = objFolder.ParseName("USB Server.exe") Set colVerbs = objFolderItem.Verbs For Each objVerb in colVerbs If Replace(objVerb.name, "&", "") = "Pin to Start Menu" Then objVerb.DoIt Next 'Pin to Start Menu - folder item (this item does not work) Set objShell = CreateObject("Shell.Application") Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS) strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path Set objFolder = objShell.Namespace("E:UsersAMaskaraMy DocumentsService Folder4XBatchFilesCleanupFTP") Set objFolderItem = objFolder.ParseName("Cleanup FTP.vbs") Set colVerbs = objFolderItem.Verbs For Each objVerb in colVerbs If Replace(objVerb.name, "&", "") = "Pin to Start Menu" Then objVerb.DoIt NextAnonymous
January 23, 2014
The comment has been removedAnonymous
February 03, 2014
I just tried running the 2nd snippet of script for pinning the calculator to the task bar as a default for all new users. However when I create a new user, the calculator shortcut doesn't appear in the task bar. Am I missing something?Anonymous
February 03, 2014
Trying to run PinItem.cmd I get the error message "PinItem.wsf(2, 39) Windows Script Host:Cannot retrieve referrenced URL : ZTIUtility.vbs" What am I doing wrong, please helpAnonymous
February 27, 2014
Is there a way we can do this for every user in the machine at a single go instead of running it via Active Setup.Anonymous
May 07, 2014
This script works great but does anyone have an idea on how to script the pinned items position. When pinning an item I would like it to appear right next to the start menu button.Anonymous
May 19, 2014
Pingback from Pin Taskbar Items 8.1Anonymous
March 06, 2015
This worked great, awesome for putting this together. Using it on my VM's to set up all of the utilities I use and get them pinned up so I'm ready to go in much less time.Anonymous
August 11, 2015
This no longer works on Windows 10. Any ideas?Anonymous
October 11, 2015
Um, how to get this script?Anonymous
October 12, 2015
Seems this does not work as expected in Windows 10
Although the context menu entry "An Taskleiste anheften" is visible in the context menu, it is simply not collected by objFolderItem.Verbs.
This has been working with windows 8.1.Anonymous
December 12, 2015
The comment has been removedAnonymous
January 27, 2016
I have a VBS script that's very close to this one that Pins and Unpins items to the taskbar and start menu. I've ran into a bit of a snag. One of my items has a ® in the name like ("Name® Pro.lnk") and it doesn't like it. How do I make that work?Anonymous
June 26, 2017
Do wniosku należy załączyć zaświadczenie stanie zdrowia wystawione przez lekarza prowadzącego leczenie na druku ZUS N-9, które jest ważny 30 dni od daty wystawienia, wywiad zawodowy z miejsca pracy na druku ZUS N-ten za wyjątkiem gdy niezdolność postała po ustaniu tytuły ubezpieczenia lub osoba prowadzi działalność pozarolniczą, protokół powypadkowy lub kartę wypadku.