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.
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.
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?
I have the VBS file working when I execute manually but how to call it from OCT2013??
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?
Regards
Must this script be run each time the user logs in, say, within a logon script??
Or only once??
Thank you…
Justin,
Open PinItem.wsf in a text editor. The usage can be found in the script header.
Michael Murgolo
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 Murgolo
Diogo
You would have to use the TaskbarLinks setting mentioned above in unattend.xml to configure the desired initial taskbar links.
Michael Murgolo
A much simpler and free tool is now available called Taskbar Pinner:
winaero.com/comment.php to pin anything.
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 Murgolo
Philip Colmer,
Please check your shortcut file name. On my machine the .lnk file has the name "Microsoft Outlook 2010" not "Outlook 2010".
Michael Murgolo
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.
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 Murgolo
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 Murgolo
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 Murgolo
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.
Michael,
ZTI-SpecialFolderLib.vbs is a function library used by PinItem.wsf. It needs to be in the same folder as PinItem.wsf.
Michael Murgolo
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 Murgolo
Wow am I glad I found this. Thanks a lot guys.
phoeneous thanks for your unpinning script too. You almost had it. The Windows Explorer link doesn't exist in strAllUsersProgramsPath. It is in the User profile in the same location as strIEFolderPath. I've changed that variable name to strUserFolderPath and using that to remove both IE and Windows Explorer as below:
Option Explicit
Const CSIDL_COMMON_PROGRAMS = &H17
Const CSIDL_PROGRAMS = &H2
Const CSIDL_STARTMENU = &HB
Dim objShell
Dim objAllUsersProgramsFolder
Dim strAllUsersProgramsPath
Dim objUserFolder
Dim strUserFolderPath
Dim objFolderWMP
Dim objFolderItemWMP
Dim objFolderIE
Dim objFolderItemIE
Dim objFolderExp
Dim objFolderItemExp
Dim colVerbs
Dim objVerb
Set objShell = CreateObject("Shell.Application")
Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS)
strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path
Set objUserFolder = objShell.NameSpace (CSIDL_STARTMENU)
strUserFolderPath = objUserFolder.Self.Path
'Windows Media Player
Set objFolderWMP = objShell.Namespace(strAllUsersProgramsPath)
Set objFolderItemWMP = objFolderWMP.ParseName("Windows Media Player.lnk")
Set colVerbs = objFolderItemWMP.Verbs
For Each objVerb in colVerbs
If Replace(objVerb.name, "&", "") = "Unpin from Taskbar" Then objVerb.DoIt
Next
'Internet Explorer
Set objFolderIE = objShell.Namespace(strUserFolderPath & "Programs")
Set objFolderItemIE = objFolderIE.ParseName("Internet Explorer.lnk")
Set colVerbs = objFolderItemIE.Verbs
For Each objVerb in colVerbs
If Replace(objVerb.name, "&", "") = "Unpin from Taskbar" Then objVerb.DoIt
Next
'Windows Explorer
Set objFolderExp = objShell.Namespace(strUserFolderPath & "ProgramsAccessories")
Set objFolderItemExp = objFolderExp.ParseName("Windows Explorer.lnk")
Set colVerbs = objFolderItemExp.Verbs
For Each objVerb in colVerbs
If Replace(objVerb.name, "&", "") = "Unpin from Taskbar" Then objVerb.DoIt
Next
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 Murgolo
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!!
If this script is used within a logon script, does the user see the script running??
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.
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.
So my questions are:
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.
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.
Thanks in advance, your responses will be most appreciated!
email: ananth _at_ ananthonline.net
-Ananth
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!
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?
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?
How do you use the ZTI-SpecialFolderLib.vbs? I suppose, I should modify it in some way before calling it from MDT?
Thanks!
Yes – I figured it out. Thank you!
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?
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.
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
Cheers
Ah nevermind… 🙂
I found a copy here that works.
http://deploymentlive.com/blog/ZTIUtility.vbs
Cheers
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 Sousa
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.
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?
Hi Thomas,
This script helped me out a lot customizing my Windows7 image but I also ran into the same issue using the script on a Windows 7 image with multiple languages installed.
I am not a scripting king but I managed to write the following script. The script reads the current language variable from the registry. Based on this information it set a language verb variable called "PinItemtext"
Just add the code into the script and replace the verb with "PinItemtext" and it should work.
Here is the code:
————-
Option Explicit
Dim objShell
Dim strLangSet, strWinLogon, PinItemtext
strLangSet = "LastUserLangID"
strWinLogon = "HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionThemeManager"
Set objShell = CreateObject("WScript.Shell")
strLangSet = objShell.RegRead(strWinLogon & strLangSet)
Select case strLangSet
case "1033"
PinItemtext = "Pin to Taskbar"
case "1031"
PinItemtext = "An Taskleiste anheften"
case "1040"
PinItemtext = "Aggiungi alla barra delle applicazioni"
case "1043"
PinItemtext = "Aan de taakbalk vastmaken"
case "1036"
PinItemtext = "Épingler à la barre des tâches"
case "1038"
PinItemtext = "Rögzítés a tálcán"
case else
PinItemtext = "Pin to Taskbar"
End Select
Wscript.Echo PinItemtext
WScript.Quit
———
How do you UNpin the Windows Explorer icon from the taskbar? I was able to remove IE and WMP but I keep getting an error on line 45 of the script below.
[code]
Option Explicit
Const CSIDL_COMMON_PROGRAMS = &H17
Const CSIDL_PROGRAMS = &H2
Const CSIDL_STARTMENU = &HB
Dim objShell
Dim objAllUsersProgramsFolder
Dim strAllUsersProgramsPath
Dim objIEFolder
Dim strIEFolderPath
Dim objFolderWMP
Dim objFolderItemWMP
Dim objFolderIE
Dim objFolderItemIE
Dim objFolderExp
Dim objFolderItemExp
Dim colVerbs
Dim objVerb
Set objShell = CreateObject("Shell.Application")
Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS)
strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path
Set objIEFolder = objShell.NameSpace (CSIDL_STARTMENU)
strIEFolderPath = objIEFolder.Self.Path
‘Windows Media Player
Set objFolderWMP = objShell.Namespace(strAllUsersProgramsPath)
Set objFolderItemWMP = objFolderWMP.ParseName("Windows Media Player.lnk")
Set colVerbs = objFolderItemWMP.Verbs
For Each objVerb in colVerbs
If Replace(objVerb.name, "&", "") = "Unpin from Taskbar" Then objVerb.DoIt
Next
‘Internet Explorer
Set objFolderIE = objShell.Namespace(strIEFolderPath & "Programs")
Set objFolderItemIE = objFolderIE.ParseName("Internet Explorer.lnk")
Set colVerbs = objFolderItemIE.Verbs
For Each objVerb in colVerbs
If Replace(objVerb.name, "&", "") = "Unpin from Taskbar" Then objVerb.DoIt
Next
‘Windows Explorer
Set objFolderExp = objShell.Namespace(strAllUsersProgramsPath & "Accessories")
Set objFolderItemExp = objFolderExp.ParseName("Windows Explorer.lnk")
Set colVerbs = objFolderItemExp.Verbs
For Each objVerb in colVerbs
If Replace(objVerb.name, "&", "") = "Unpin from Taskbar" Then objVerb.DoIt
Next
[/code]
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?
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?
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!
Hi Michae,
Great script – very useful.
Is it possible to unpin items again with your script? And how would that be done?
Cheers
Also, remember that these options are MUI aware, so if you use them on a TS remember to add settings for each language…
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
'*
'* Output: Help messages are displayed on screen.
'*
'********************************************************************
Sub ShowUsage()
WScript.Echo "This script is used to Pin items to the Start Menu or Taskbar."
WScript.Echo ""
WScript.Echo "Usage: cscript " & WScript.ScriptName & " [options]"
WScript.Echo ""
WScript.Echo "Options:"
WScript.Echo ""
WScript.Echo " /item:<PathName> Path of item to pin."
WScript.Echo ""
WScript.Echo " /taskbar (Optional) Pin to Taskbar instead of Start Menu."
WScript.Echo ""
WScript.Echo " /unpin (Optional) Unpin from instead of Pin to."
WScript.Echo ""
WScript.Echo " /? (Optional) Displays this help text."
WScript.Echo ""
WScript.Echo ""
WScript.Echo ""
End Sub
'**************************************
OK, So I am going Crazy here.
All of this is on Windows 7 Pro..
I am trying to Create a Shortcut that points to a web URL, and pin that to the Taskbar.
I use VB Code to create a .lnk file for Internet Explorer pointing to the web URL I want like this
Set Shell = CreateObject("WScript.Shell")
StartMenuPath = Shell.SpecialFolders("AllUsersStartMenu")
Set link = Shell.CreateShortcut(StartMenuPath & "Somewhere out there.lnk")
link.Arguments = "http://www.somewhere.com"
link.Description = "Somwhere Out There"
link.IconLocation = "C:IconsSomewhere.ico,0"
link.TargetPath = "C:Program FilesInternet Exploreriexplore.exe"
link.WindowStyle = 3
link.WorkingDirectory = ""
link.Save
This creates the link just great.
Then I try to Pin it to the Task Bar like this
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 & "")
Set objFolderItem = objFolder.ParseName("Somewhere out there.lnk")
Set colVerbs = objFolderItem.Verbs
For Each objVerb in colVerbs
If Replace(objVerb.name, "&", "") = "Pin to TaskBar" Then objVerb.DoIt
Next
It doesn't pin it to the Task bar and if I right click the Shortcut, the "Pin to Taskbar" isn't shown
i also tried the followintg:
1) Right click the desktop and select new shortcut
2) Point the Shortcut to "c:program filesinternet exploreriexplore.exe" http://www.somwhere.com
3) Give it the name "Somewhere out there, and click finish.
4) Right Click the shortcut and "Pin to Taskbar" is shown
5) Rename the shortcut to "Somewhere on the web"
6) Right click the shortcut and "Pin to Taskbar" is gone gone gone….
How can I retain what little hair I have left, and get the Shortcut to a web destination pinned to the task bar? this has to be done with code as it needs to be an automated process..
-Mark
I am struggling on how to implement this script. There are many files in this zip folder but there is no readme.txt. From the posts here I am surmising that PinItem.vbs is stand alone. However PinItem.wsf requries PinItem.cmd, ListVerbs.vbs and ZTI-SpecialFolderLib.vbs and some other file that is not even included in the zip to be in the same folder in order for the script to work. This file is ZTIUtility.vbs. It was not included because "is already part of MDT I did not see the need to redistribute another copy."
Since I am stupid and I could not find that file I attempted to use the PinItem.vbs in conjunction with the PinItem.cmd contents.
I have server 2008 with a User Login Batch script. In the batch file I copied the PinItem.cmd contents and made the following changes. The PinItem.vbs script is in the same folder as my login.bat. None of the variations I tried work. Can anyone give me a point or nudge in the correct direction. This is so fustrating and I feel I am so close. Thanks.
:: ********************************************************************************
:: Sample command shell script to demonstrate the usage of PinItem.vbs
:: ********************************************************************************
:: ********************************************************************************
:: Clear all environment variables
:: ********************************************************************************
@echo off
set ITEM=
set TASKBAR=
set USAGE=
:: ********************************************************************************
:: Set environment variables for PinItem.vbs switch values
:: Commemt out a line to not use a switch
:: ********************************************************************************
:: set ITEM=/item:"%windir%System32calc.exe"
:: set ITEM=/item:"%%CSIDL_COMMON_PROGRAMS%%AccessoriesCalculator.lnk"
:: set TASKBAR=/taskbar
:: set USAGE=/?
:: ********************************************************************************
:: Execute PinToStartMenu.vbs
:: ********************************************************************************
echo on
:: Pin to Start Menu
:: cscript PinItem.wfs %ITEM% %USAGE%
:: Pin to Taskbar – None of these variations work.
cscript %SCRIPTROOT%/PinItem.vbs /item:"C:ProgramDataMicrosoftWindowsStart MenuProgramsMicrosoft OfficeMicrosoft Excel 2010.lnk" /taskbar
cscript.exe %SCRIPTROOT%/PinItem.vbs /item: "C:ProgramDataMicrosoftWindowsStart MenuProgramsMicrosoft OfficeMicrosoft PowerPoint 2010.lnk" /taskbar
cscript.exe PinItem.vbs /item: "C:ProgramDataMicrosoftWindowsStart MenuProgramsMicrosoft OfficeMicrosoft Word 2010.lnk" /taskbar
cscript PinItem.vbs /item:"C:ProgramDataMicrosoftWindowsStart MenuProgramsMicrosoft OfficeMicrosoft Outlook 2010.lnk" /taskbar
cscript PinItem.vbs /item:"C:Program FilesMicrosoft OfficeOffice1Excel.exe" /taskbar
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 :- )
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.
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?
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?
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.
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?
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.
thanks
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.
thanks
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?
on windows 8 this works for the taskbar, but not the start screen…
This was just what I was looking for…….Thanks!
Hello,
is there also a script available for windows 8/server 2012?
Thx
anyone able to get this script to work with .lnk-files that include "em dashes"?
thanks a lot!
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 http://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 http://FTP.vbs"😉
Set colVerbs = objFolderItem.Verbs
For Each objVerb in colVerbs
If Replace(objVerb.name, "&", "") = "Pin to Start Menu" Then objVerb.DoIt
Next
I searched all over for a reliable way to pin items to the taskbar in Windows 8 but couldn't find an easy way deploy them after the machine has been deployed. I managed in the end to create a group policy preference where it would dump the .bat file which in turn calls the pinitem.vbs script and creates them. Messy but it works.
http://www.blackforce.co.uk/2014/01/23/how-to-pin-programs-to-windows-8-taskbar-using-group-policy-preferences-gpo
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?
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 help
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.
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.
Pingback from Pin Taskbar Items 8.1
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.
This no longer works on Windows 10. Any ideas?
Um, how to get this script?
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.
The script is nice but it doesn't do it for all users. What's the point? How the hell hasn't Microsoft got a tool to customize the start menu by not is beyond me.
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?