locked
Add desired icons to taskbar and start menu using scripts RRS feed

  • Question

  • Hi,

    I need to add specific icons/programs to the taskbar and start menu in our custom image. With Windows Vista, I would pin items on a reference computer that has the complete image less customizations. After the items are pinned, I would export a certain registry key and then import it during image deployment using a simple script.

    Is this the same case with Windows 7? Would anyone know which keys to export for the start menu and taskbar? Or is there a better way to programmatically pin items to the start menu and taskbar?

    Thanks for your help!

    Rob
    Tuesday, February 16, 2010 4:49 PM

Answers

  • Here is the code I used. You can modify it to pin other programs if needed. I have also added a section that pins Notepad to the start menu as well:

     

    'Declare variables
    Dim arrOfficeArray (4)
    Dim strOCSIcon
    Dim strCalculatorIcon
    Dim strNotepadIcon
    Dim i
    
    'Declare constants
    Const CSIDL_COMMON_PROGRAMS = &H17 
    Const CSIDL_PROGRAMS = &H2
    
    'Initialize variables
    arrOfficeArray(0) = "Microsoft Office Outlook 2007.lnk"
    arrOfficeArray(1) = "Microsoft Office Word 2007.lnk"
    arrOfficeArray(2) = "Microsoft Office Excel 2007.lnk"
    arrOfficeArray(3) = "Microsoft Office PowerPoint 2007.lnk"
    arrOfficeArray(4) = "Microsoft Office OneNote 2007.lnk"
    strOCSIcon = "Microsoft Office Communicator 2007 R2.lnk"
    strCalculatorIcon = "Calculator.lnk"
    strNotepadIcon = "notepad.exe"
    
    'Pin to taskbar - Outlook, Word, Excel, PowerPoint, OneNote, OCS
    Set objShell = CreateObject("Shell.Application")
    Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS) 
    strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path 
    Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Microsoft Office")
    For i = 0 To 4
    	Set objFolderItem = objFolder.ParseName(arrOfficeArray(i)) 
    	Set colVerbs = objFolderItem.Verbs 
    	For Each objVerb in colVerbs 
    	    If Replace(objVerb.name, "&", "") = "Pin to Taskbar" Then objVerb.DoIt 
    	Next
    Next
    
    'Pin to taskbar - Office Communicator
    Set objFolder = objShell.Namespace(strAllUsersProgramsPath)
    Set objFolderItem = objFolder.ParseName(strOCSIcon) 
    Set colVerbs = objFolderItem.Verbs 
    For Each objVerb in colVerbs 
        If Replace(objVerb.name, "&", "") = "Pin to Taskbar" Then objVerb.DoIt 
    Next
    
    'Pin to Start Menu - Calculator
    Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Accessories")
    Set objFolderItem = objFolder.ParseName(strCalculatorIcon) 
    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 - Notepad
    Set objFolder = objShell.Namespace("C:\windows\system32")
    Set objFolderItem = objFolder.ParseName(strNotepadIcon) 
    Set colVerbs = objFolderItem.Verbs 
    For Each objVerb in colVerbs 
        If Replace(objVerb.name, "&", "") = "Pin to Start Menu" Then objVerb.DoIt 
    Next
    • Marked as answer by robwm1 Friday, April 9, 2010 3:38 PM
    Friday, April 9, 2010 3:36 PM
  • Hi Rob,

    New taskbar is a great feature in Windows 7, as you may know, you are in complete control of the icons that are placed on the taskbar. What this means is that only you can add or remove icons from the taskbar. No method is being provided for program installers to place icons on the taskbar. This is a huge change from the behavior of the previous Quick Launch bar.

    I’ve found there is a pretty good article about scripting add shortcuts to the taskbar and start menu and hope it’s helpful.

    Pin Items to the Start Menu or Windows 7 Taskbar via Script
    http://blogs.technet.com/deploymentguys/archive/2009/04/08/pin-items-to-the-start-menu-or-windows-7-taskbar-via-script.aspx

    PS: this blog has the source code in attachment and you can check them for detailed info.

    If there is any further problem about scripting code, I recommend you open a thread to Official Scripting Guys Forum in Technet so those coders can help you fix the issue in a timely manner.
    http://social.technet.microsoft.com/Forums/en/ITCG/threads

    Wednesday, February 17, 2010 3:13 AM

All replies

  • Microsoft said that they have specifically blocked this in Windows 7 because the user should be in control, not some other program developer that thinks they know best.

    That's a paraphrase... to read the real quote, check out the Microsoft Developer Blog (written by the engineers who created Windows 7):  http://blogs.msdn.com/e7




    If this was helpful, please vote by clicking the green triangle. If it solves the issue, click Propose as Answer. Thanks!
    Wednesday, February 17, 2010 3:12 AM
  • Hi Rob,

    New taskbar is a great feature in Windows 7, as you may know, you are in complete control of the icons that are placed on the taskbar. What this means is that only you can add or remove icons from the taskbar. No method is being provided for program installers to place icons on the taskbar. This is a huge change from the behavior of the previous Quick Launch bar.

    I’ve found there is a pretty good article about scripting add shortcuts to the taskbar and start menu and hope it’s helpful.

    Pin Items to the Start Menu or Windows 7 Taskbar via Script
    http://blogs.technet.com/deploymentguys/archive/2009/04/08/pin-items-to-the-start-menu-or-windows-7-taskbar-via-script.aspx

    PS: this blog has the source code in attachment and you can check them for detailed info.

    If there is any further problem about scripting code, I recommend you open a thread to Official Scripting Guys Forum in Technet so those coders can help you fix the issue in a timely manner.
    http://social.technet.microsoft.com/Forums/en/ITCG/threads

    Wednesday, February 17, 2010 3:13 AM
  • Shawn,

    I read through that link and I didn't see anything saying they specifically blocked adding shortcuts to the taskbar and start menu. They did say that they felt that the interface was configured in way that would be useful to a wide number of users without having to change anything. That being said, the default configuration doesn't meet our organization's needs and still requires customization. Gordon below has some good info on customizing the taskbar and start menu. Even if you couldn't do this programatically, your customizations to the OS have to be stored somewhere on your hard drive, usually in the registry by my experinece, which can be exported and then imported during image deployment.

    Thanks a lot for the link! That blog is a really good find and has some great information!

    Rob
    Wednesday, February 17, 2010 2:41 PM
  • Gordon,

    This looks really hopeful! I will look this over and report back my experince in using these scripting methods.

    Thanks a lot for your help!

    Rob
    Wednesday, February 17, 2010 2:42 PM
  •   Gordon,

      Just to follow-up, I was able to modify the code given in the example of your first link to pin the items I needed on the Start Menu and Taskbar. That was a pretty good find and thanks for pointing it out.

      If anyone tries this out, please be aware that you can only pin shortcuts and not all shortcuts I found out. I still don't know how to get Notepad pinned to the Start Menu even if I do create a shortcut for Notepad. I am guessing that these types of shortcuts have to be copied to multiple places in the filesystem but I don't know which locations at this time. If you use this sample code to pin anything other than an shortcut, the script will throw an error. That's your first clue that the object you are trying to pin cannot be done in this way.

    Thanks again for your help!

    Rob

    Wednesday, April 7, 2010 5:44 PM
  • Here is the code I used. You can modify it to pin other programs if needed. I have also added a section that pins Notepad to the start menu as well:

     

    'Declare variables
    Dim arrOfficeArray (4)
    Dim strOCSIcon
    Dim strCalculatorIcon
    Dim strNotepadIcon
    Dim i
    
    'Declare constants
    Const CSIDL_COMMON_PROGRAMS = &H17 
    Const CSIDL_PROGRAMS = &H2
    
    'Initialize variables
    arrOfficeArray(0) = "Microsoft Office Outlook 2007.lnk"
    arrOfficeArray(1) = "Microsoft Office Word 2007.lnk"
    arrOfficeArray(2) = "Microsoft Office Excel 2007.lnk"
    arrOfficeArray(3) = "Microsoft Office PowerPoint 2007.lnk"
    arrOfficeArray(4) = "Microsoft Office OneNote 2007.lnk"
    strOCSIcon = "Microsoft Office Communicator 2007 R2.lnk"
    strCalculatorIcon = "Calculator.lnk"
    strNotepadIcon = "notepad.exe"
    
    'Pin to taskbar - Outlook, Word, Excel, PowerPoint, OneNote, OCS
    Set objShell = CreateObject("Shell.Application")
    Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS) 
    strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path 
    Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Microsoft Office")
    For i = 0 To 4
    	Set objFolderItem = objFolder.ParseName(arrOfficeArray(i)) 
    	Set colVerbs = objFolderItem.Verbs 
    	For Each objVerb in colVerbs 
    	    If Replace(objVerb.name, "&", "") = "Pin to Taskbar" Then objVerb.DoIt 
    	Next
    Next
    
    'Pin to taskbar - Office Communicator
    Set objFolder = objShell.Namespace(strAllUsersProgramsPath)
    Set objFolderItem = objFolder.ParseName(strOCSIcon) 
    Set colVerbs = objFolderItem.Verbs 
    For Each objVerb in colVerbs 
        If Replace(objVerb.name, "&", "") = "Pin to Taskbar" Then objVerb.DoIt 
    Next
    
    'Pin to Start Menu - Calculator
    Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Accessories")
    Set objFolderItem = objFolder.ParseName(strCalculatorIcon) 
    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 - Notepad
    Set objFolder = objShell.Namespace("C:\windows\system32")
    Set objFolderItem = objFolder.ParseName(strNotepadIcon) 
    Set colVerbs = objFolderItem.Verbs 
    For Each objVerb in colVerbs 
        If Replace(objVerb.name, "&", "") = "Pin to Start Menu" Then objVerb.DoIt 
    Next
    • Marked as answer by robwm1 Friday, April 9, 2010 3:38 PM
    Friday, April 9, 2010 3:36 PM
  • An alternative method...

    The following was put together based on ideas from other techs/coders and assumes that you are using an english version of Win7, as it uses Verbs (the items you see when you right click a file) to "Pin to Taskbar". Other languages will need to replace the text accordingly.

    These two scripts and batch file that I put together for my agency are currently being used, and are implemented via SCCM. It is applied on first logon for any user to any PC.

    We wanted to programmatically configure the icons on the Taskbar as follows -
    Remove:
    Windows Media Player

    Add:
    Outlook

    Change:
    Windows Explorer (Libraries) to Windows Explorer (Computer)

    Create the three files and put them in the same folder...

    ***************************************
    Name this script (Pin.vbs)
    ***************************************

    Set objShell = CreateObject("Shell.Application")
    Set filesystem = CreateObject("scripting.Filesystemobject")
    If filesystem.FileExists(Wscript.Arguments(0)) Then
     Set objFolder = objShell.Namespace(filesystem.GetParentFolderName(Wscript.Arguments(0)))
     Set objFolderItem = objFolder.ParseName(filesystem.GetFileName(WScript.Arguments(0)))
     Set colVerbs = objFolderItem.Verbs
     
     Select case WScript.Arguments(1)
      case 0
       For Each objVerb in colVerbs
        If Replace(objVerb.name, "&", "") = "Unpin from Taskbar" Then objVerb.DoIt
       Next
      case 1
       For Each objVerb in colVerbs
        If Replace(objVerb.name, "&", "") = "Pin to Taskbar" Then objVerb.DoIt
       Next
      case 2
       For Each objVerb in colVerbs
        If Replace(objVerb.name, "&", "") = "Install" Then objVerb.DoIt
       Next
     End Select
    End If

    ***************************************

    The following script can be used to programmatically create Shortcuts. I could have used a preconfigured .lnk file and just xcopy'd it, but this is just cooler :)

    You'll notice there are commented (') out sections for Shortcut Name. You can use one of the three depending on the way you'd like to reference the destination folder for the icon being created.

    ***************************************
    Name this script (MyExplorerLnk.vbs)
    ***************************************

    Set WshShell = WScript.CreateObject("WScript.Shell" )

    ' Shortcut Name (Special Folders)
    ' strLocation = WshShell.SpecialFolders("AllUsersDesktop" )
    ' Set oShellLink = WshShell.CreateShortcut(strLocation & "\Windows Explorer.lnk" )

    ' Shortcut Name (Environment Variables)
    strLocation = WshShell.ExpandEnvironmentStrings("%APPDATA%" )
    set oShellLink = WshShell.CreateShortcut(strLocation & "\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Windows Explorer.lnk" )

    ' Shortcut Name (Normal Path)
    ' Set oShellLink = WshShell.CreateShortcut("C:\Windows Explorer.lnk" )

    ' Path to application
    oShellLink.TargetPath = "%Windir%\explorer.exe"

    ' Command line arguments
    oShellLink.Arguments = " shell:MyComputerFolder"

    ' Window Style
    oShellLink.WindowStyle = 1

    ' Hotkey
    oShellLink.Hotkey = ""

    ' Icon for Shortcut
    oShellLink.IconLocation = "%windir%\explorer.exe"

    ' Shortcut Comment
    oShellLink.Description = "Windows Explorer"

    ' Working Directory
    oShellLink.WorkingDirectory = ""

    oShellLink.Save

    ***************************************

    The following Batch file is used to launch the above scripts, and also documents the use of Pin.vbs

    Our agency primarily uses Win XP, Win 7 x86, and Win 7 x64... hence the limited version check.

    ***************************************
    Name this Batch file (TBcustom.cmd)
    ***************************************

    :: Set Environment
    @ECHO OFF
    CLS
    TITLE Taskbar Customization Tool
    COLOR 3f
    PROMPT $s

    SET UsrPinTBar="%APPDATA%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar"

    :: *** Usage - Pin.vbs
    :: *** WScript.exe "%~dp0\%~dp0\Pin.vbs" [drive:][path]filename [Argument]
    :: *** [Arguments] = 0 1 2
    :: *** 0 = Unpin from Taskbar
    :: *** 1 = Pin to Taskbar
    :: *** 2 = Install

    ::  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    :: Identify Windows Version
    :: *** Assign ver output to variable VerResult ***
    FOR /F "delims=" %%A IN ('ver') Do Set VerResult=%%A

    :: *** Parse VerResult and assign variable according to OS version ***
    ECHO "%VerResult%" | find "Version 6.1" > nul && GOTO Windows7Var
    ECHO "%VerResult%" | find "Version 6.0" > nul && GOTO WindowsVistaVar
    ECHO "%VerResult%" | find "Version 5" > nul && GOTO :WindowsXPVar
    ECHO Error - Unexpected Version Information
    GOTO EOF

    ::  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    :Windows7Var
    IF %processor_architecture%==x86 GOTO 7x86Var
    IF %processor_architecture%==AMD64 GOTO 7x64Var
    IF %processor_architecture%==IA64 GOTO 7x64Var
    GOTO EOF

    ::  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    :WindowsVistaVar
    ECHO This PC is running Windows Vista
    :: *** Unsupported ***
    GOTO EOF

    ::  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    :WindowsXPVar
    ECHO This PC is running Windows XP
    :: *** Unsupported ***
    GOTO EOF

    ::  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    :7x86Var
    ECHO This PC is running Windows 7 32Bit

    :: *** REMOVE WINDOWS EXPLORER ***
    WScript.exe "%~dp0\Pin.vbs" "%APPDATA%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Windows Explorer.lnk" 0
    IF EXIST "%UsrPinTBar%\Windows Explorer.lnk" DEL /q /f "%UsrPinTBar%\Windows Explorer.lnk"

    :: *** REMOVE WINDOWS MEDIA PLAYER ***
    WScript.exe "%~dp0\Pin.vbs" "%APPDATA%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Windows Media Player.lnk" 0
    IF EXIST "%UsrPinTBar%\Windows Media Player.lnk" DEL /q /f "%UsrPinTBar%\Windows Media Player.lnk"

    :: *** ADD CUSTOM WINDOWS EXPLORER (opens to shell:MyComputerFolder) ***
    WScript.exe "%~dp0\Pin.vbs" %windir%\explorer.exe 1
    WScript.exe "%~dp0\MyExplorerLnk.vbs"

    :: *** ADD OUTLOOK***
    WScript.exe "%~dp0\Pin.vbs" "%ProgramFiles%\Microsoft Office\Office14\Outlook.exe" 1
    GOTO EOF

    ::  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    :7x64Var
    ECHO This PC is running Windows 7 64Bit

    :: *** REMOVE WINDOWS EXPLORER ***
    WScript.exe "%~dp0\Pin.vbs" "%APPDATA%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Windows Explorer.lnk" 0
    IF EXIST "%UsrPinTBar%\Windows Explorer.lnk" DEL /q /f "%UsrPinTBar%\Windows Explorer.lnk"

    :: *** REMOVE WINDOWS MEDIA PLAYER ***
    WScript.exe "%~dp0\Pin.vbs" "%APPDATA%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Windows Media Player.lnk" 0
    IF EXIST "%UsrPinTBar%\Windows Media Player.lnk" DEL /q /f "%UsrPinTBar%\Windows Media Player.lnk"

    :: *** ADD CUSTOM WINDOWS EXPLORER (opens to shell:MyComputerFolder)***
    WScript.exe "%~dp0\Pin.vbs" %windir%\explorer.exe 1
    WScript.exe "%~dp0\MyExplorerLnk.vbs"

    :: *** ADD OUTLOOK***
    WScript.exe "%~dp0\Pin.vbs" "%ProgramFiles% (x86)\Microsoft Office\Office14\Outlook.exe" 1
    GOTO EOF

    ::  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    :EOF
    EXIT

    ***************************************

    This method is what worked best for our particular needs, as our agency deploys virgin OS images and customizes and deploys software as SCCM task sequences and packages. It also does not dictate that a user can't customize the Taskbar as they see fit, and won't remove their own customizations, as would other methods posted that replace the Taskband registry values.

    I hope this helps, and feel free to criticize or ask for assistance with it!


    - RonSum
    • Proposed as answer by Yuri M Kuit Tuesday, July 1, 2014 8:53 AM
    Monday, September 5, 2011 5:01 PM