Copy Taskbar Icons Windows 7 Sysprep

windows7-quicklaunch

This is the old version, please see the new Copy Taskbar Icons Windows 7 Sysprep v2.

Ok, you can thank a colleague of mine (Dinyero Johnson) for this new single vbs script that now copies the taskbar icons and deletes itself.

The vbs script is a little nicer than version one (CMD) because it runs without any windows and in my opinion vbs scripts just run smoother :). Also, it is a single file and the tutorial has less steps.

So for all of you who grabbed version one, lol, grab version 2!!! And if you are using WIM images, you can simply mount your image, replace the script, and unmount/commit.

Repeat instructions are below:

When running sysprep in Windows 7 with the unattend.xml file, you will probably notice that the taskbar icons are something that don’t copy over. Well that is because the icons are not part of the users profile. So the copyprofile=true command does work for almost everything, but it doesn’t copy over your taskbar icons. So here is a script that will do it for you.

Step #1

Download the vbs script (11kb). Click Here to Download or Right Click and Save Target As….
You might have to remove the .txt extension when you are downloading the script. You are going to drop this script into the correct place during audit mode.

Option Explicit

Const CSIDL_COMMON_PROGRAMS = &H17
Const CSIDL_PROGRAMS = &H2
Const CSIDL_STARTMENU = &HB

Dim objShell, objFSO
Dim objCurrentUserStartFolder
Dim strCurrentUserStartFolderPath
Dim objAllUsersProgramsFolder
Dim strAllUsersProgramsPath
Dim objFolder
Dim objFolderItem
Dim colVerbs
Dim objVerb

Set objShell = CreateObject("Shell.Application")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objCurrentUserStartFolder = objShell.NameSpace (CSIDL_STARTMENU)
strCurrentUserStartFolderPath = objCurrentUserStartFolder.Self.Path
Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS)
strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path

' - Remove pinned items -

'Internet Explorer
If objFSO.FileExists(strCurrentUserStartFolderPath & "\Programs\Internet Explorer.lnk") Then
    Set objFolder = objShell.Namespace(strCurrentUserStartFolderPath & "\Programs")
    Set objFolderItem = objFolder.ParseName("Internet Explorer.lnk")
    Set colVerbs = objFolderItem.Verbs
    For Each objVerb in colVerbs
        If Replace(objVerb.name, "&", "") = "Unpin from Taskbar" Then objVerb.DoIt
    Next
End If

'Windows Explorer
If objFSO.FileExists(strCurrentUserStartFolderPath & "\Programs\Accessories\Windows Explorer.lnk") Then
    Set objFolder = objShell.Namespace(strCurrentUserStartFolderPath & "\Programs\Accessories")
    Set objFolderItem = objFolder.ParseName("Windows Explorer.lnk")
    Set colVerbs = objFolderItem.Verbs
    For Each objVerb in colVerbs
        If Replace(objVerb.name, "&", "") = "Unpin from Taskbar" Then objVerb.DoIt
    Next
End If
'Windows Media Player
If objFSO.FileExists(strAllUsersProgramsPath & "\Windows Media Player.lnk") Then
    Set objFolder = objShell.Namespace(strAllUsersProgramsPath)
    Set objFolderItem = objFolder.ParseName("Windows Media Player.lnk")
    Set colVerbs = objFolderItem.Verbs
    For Each objVerb in colVerbs
        If Replace(objVerb.name, "&", "") = "Unpin from Taskbar" Then objVerb.DoIt
    Next
End If

' - Pin to Taskbar -

'Windows Explorer
If objFSO.FileExists(strCurrentUserStartFolderPath & "\Programs\Accessories\Windows Explorer.lnk") Then
	Set objFolder = objShell.Namespace(strCurrentUserStartFolderPath & "\Programs\Accessories")
	Set objFolderItem = objFolder.ParseName("Windows Explorer.lnk")
	Set colVerbs = objFolderItem.Verbs
	For Each objVerb in colVerbs
		If Replace(objVerb.name, "&", "") = "Pin to Taskbar" Then objVerb.DoIt
	Next
End If

'Internet Explorer
If objFSO.FileExists(strCurrentUserStartFolderPath & "\Programs\Internet Explorer.lnk") Then
    Set objFolder = objShell.Namespace(strCurrentUserStartFolderPath & "\Programs")
    Set objFolderItem = objFolder.ParseName("Internet Explorer.lnk")
    Set colVerbs = objFolderItem.Verbs
    For Each objVerb in colVerbs
        If Replace(objVerb.name, "&", "") = "Pin to Taskbar" Then objVerb.DoIt
    Next
End If

'Mozilla Firefox
If objFSO.FileExists(strAllUsersProgramsPath & "\Mozilla Firefox\Mozilla Firefox.lnk") Then
	Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Mozilla Firefox")
	Set objFolderItem = objFolder.ParseName("Mozilla Firefox.lnk")
	Set colVerbs = objFolderItem.Verbs
	For Each objVerb in colVerbs
		If Replace(objVerb.name, "&", "") = "Pin to Taskbar" Then objVerb.DoIt
	Next
End If

'Microsoft Word 2010
If objFSO.FileExists(strAllUsersProgramsPath & "\Microsoft Office\Microsoft Word 2010.lnk") Then
	Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Microsoft Office")
	Set objFolderItem = objFolder.ParseName("Microsoft Word 2010.lnk")
	Set colVerbs = objFolderItem.Verbs
	For Each objVerb in colVerbs
		If Replace(objVerb.name, "&", "") = "Pin to Taskbar" Then objVerb.DoIt
	Next
End If

'Microsoft Excel 2010
If objFSO.FileExists(strAllUsersProgramsPath & "\Microsoft Office\Microsoft Excel 2010.lnk") Then
	Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Microsoft Office")
	Set objFolderItem = objFolder.ParseName("Microsoft Excel 2010.lnk")
	Set colVerbs = objFolderItem.Verbs
	For Each objVerb in colVerbs
		If Replace(objVerb.name, "&", "") = "Pin to Taskbar" Then objVerb.DoIt
	Next
End If

'Microsoft Outlook 2010
If objFSO.FileExists(strAllUsersProgramsPath & "\Microsoft Office\Microsoft Outlook 2010.lnk") Then
	Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Microsoft Office")
	Set objFolderItem = objFolder.ParseName("Microsoft Outlook 2010.lnk")
	Set colVerbs = objFolderItem.Verbs
	For Each objVerb in colVerbs
		If Replace(objVerb.name, "&", "") = "Pin to Taskbar" Then objVerb.DoIt
	Next
End If

'Windows Media Player
If objFSO.FileExists(strAllUsersProgramsPath & "\Windows Media Player.lnk") Then
	Set objFolder = objShell.Namespace(strAllUsersProgramsPath)
	Set objFolderItem = objFolder.ParseName("Windows Media Player.lnk")
	Set colVerbs = objFolderItem.Verbs
	For Each objVerb in colVerbs
		If Replace(objVerb.name, "&", "") = "Pin to Taskbar" Then objVerb.DoIt
	Next
End If

'Delete the script
DeleteSelf

Sub DeleteSelf()       
        Dim objFSO
        'Create a File System Object
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        'Delete the currently executing script
        objFSO.DeleteFile WScript.ScriptFullName
        Set objFSO = Nothing
End Sub

Step 2

Copy the vbs script into the startup folder in the start menu.

Step 3

The vbs script unpins WMP, IE, and Windows Explorer and then repins the icons in the order you want. My file has this order:

Windows Explorer, IE, Firefox, Word, Excel, Outlook, WMP

Step 4

Now run sysprep as you normally would and the script is copied into the default profile. That means for every new user, the script pins the icons in the order you want, the script then deletes itself and never runs again. For the correct procedure on sysprepping your machine, read my Windows 7 Sysprep Tutorial.

Incoming search terms:

  • settaskbar vbs
  • set taskbar vbs
  • copy-taskbar-icons-windows-7-sysprep-v2
  • windows 7 sysprep taskbar icons
  • copy taskbar icons windows 7 sysprep
  • Pingback: Sysprep a Windows 7 Machine

  • Pingback: Copy Taskbar Icons Windows 7 Sysprep v2 - Blog.BrianLeeJackson.com

  • Mike

    Wish I had the experience to do this myself, but it be much more useful if this script filled an array with the current taskbar items, then re-populated these items on the taskbar on next login. That way any icon could be managed, not just the ones mentioned above, and hand-editing the code for each change wouldn’t be necessary.

  • Allen

    Thank you for showing us this. One question when I hold my course over the Outlook, Mozilla, Word and Excell icons on the taskbar the names show up as name (2) for example Outlook shows Microsoft Outlook 2010 (2) Windows Explorer and Internet Explorer are ok.

    What would cause this and is there a fix for it?

    • Allen

      Never mind I figured it out.

      • Trenton

        Please post how you fixed this

    • RaviU

      How did you get this (2) next to icon name removed.
      Thanks in advance.

  • Peter

    Thank you so much for the script and for the Sysprep tutorial, both have been incredibly insightful. 1 question regarding the pinned taskbar vbs script. It works great (I modified to use with Office 2007 and removed the links to Firefox), however when it first runs on a users’ startup it asks them for permission to run, is there a way for it to run ‘quiet’ so they don’t have the option to not run it?

    • McCleary

      How did you get the Office 2007 links to work?

    • Nicholas

      I have a sysprep batch file that inserts this into the correct folder just before sysprep (or it will delete itself on next restart), and sets users to have ‘full control’ permission. You can do this manually, but I love scripting things… :) I have had no issues with any users running the script. It is silent and takes only a few seconds to complete when they log in. Here’s my code;

      copy firstlogin.vbs "C:\Users\administrator\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"
      cacls "C:\Users\administrator\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\firstlogin.vbs" /e /c /g Users:f

  • Pingback: Ramblings of Mad Windows Administrator… » Pre-Image Process for MDT

  • Keith

    I use this to delete all the current taskbar icons. Hope if helps.


    Dim objTaskBarFolder, objLoopFolder, objFile
    Dim AppData, CurDir
    AppData = WshShell.ExpandEnvironmentStrings("%APPDATA%")
    CurDir = objFSO.GetParentFolderName(Wscript.ScriptFullName)

    ' - REMOVE PINNED ITEMS -

    objTaskBarFolder = AppData & "\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar"
    Set objLoopFolder = objFSO.GetFolder(objTaskBarFolder)

    For Each objFile in objLoopFolder.Files
    If Right(objFile.Name,4) = ".lnk" Then

    Set objFolder = objShell.Namespace(objTaskBarFolder)
    Set objFolderItem = objFolder.ParseName(objFile.Name)
    Set colVerbs = objFolderItem.Verbs
    For Each objVerb in colVerbs
    If Replace(objVerb.name, "&", "") = "Unpin from Taskbar" Then objVerb.DoIt
    Next

    End If
    Next

    • Scott

      Hi Kieth, this code does not work for me. Complains about WshShell. Object Required. When i do a Dim WshShell and rerun, complains about the appdata line? Any help would be great, this is exactly what im looking for, ta

  • Steve

    Thank you for proving these wonderful scripts. That’s kind of you to share.

    @ Keith
    Similar to the taskbar, Windows 7 always adds some default programs to the Start Menu of each user that logons on to the PC. What parts of your script I need to modify so that it can delete all the current start menu icons before I add the icon I want?

    Also, I want to include your portion of the script in the longer script Brian Jackson provided. How and where should I integrate it? For example, should I put the following part of your script at the top of Brian’s script file?
    Dim objTaskBarFolder, objLoopFolder, objFile
    Dim AppData, CurDir
    AppData = WshShell.ExpandEnvironmentStrings(“%APPDATA%”)
    CurDir = objFSO.GetParentFolderName(Wscript.ScriptFullName)

    Thank you Guys.

  • Raffael

    Thanks for the VBS-File.

    It’s only working in english-version of Windows 7 ?!

    I have change the “Pin to taskbar” String and all other Links are working with german os but not with this script ?!

    may you can highlight the strings which i have to change for working with other OS types ?!

    thanks very much

    regards
    raffael

  • bkz81

    How can i go about adding the “Flip 3D” to the taskbar.

    Thanks.

    • http://theitbros.com Brett Jackson

      If you are on Windows 7, there is no shortcut setup by default for the “Flip 3D” feature (switch between windows). However, if you are wanting to be able to pin this feature as a shortcut to the taskbar, or use it in your vbs script, you can create your own shorcut that links to this feature. To save time, here is a good tutorial on how to create a shortcut for this in windows 7. (They also have one already made that you can download)

      How to Add a Flip 3D Switch Between Windows Shortcut in Windows 7

  • bkz81

    Thanks for the info. I was able to add Flip 3D, but when execute the script everything launches and gets pinned except firefox does show up nor get pinned. Was something changed when firefox upgraded to version 4? Thanks again.

    • http://theitbros.com Brett Jackson

      Yes, this did change in firefox version 4. The location of the shorcut we are pointing to in the vbs script is now different. Here is the way you are probably currently pinning firefox to the taskbar. (This is copied from the vbs script we provided in this post)

      If objFSO.FileExists(strAllUsersProgramsPath & "\Mozilla Firefox\Mozilla Firefox.lnk") Then
      Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Mozilla Firefox")
      Set objFolderItem = objFolder.ParseName("Mozilla Firefox.lnk")
      Set colVerbs = objFolderItem.Verbs
      For Each objVerb in colVerbs
      If Replace(objVerb.name, "&", "") = "Pin to Taskbar" Then objVerb.DoIt
      Next
      End If

      However, in firefox 4, the shorcut is no longer inside a ‘Mozilla Firefox’ folder. It is simply in the start menu by itself. (similiar to the location of windows media player) So if you simply remove the parts above with a strike through them, your ‘pin firefox’ section should now look like this.

      If objFSO.FileExists(strAllUsersProgramsPath & "\Mozilla Firefox.lnk") Then
      Set objFolder = objShell.Namespace(strAllUsersProgramsPath)
      Set objFolderItem = objFolder.ParseName("Mozilla Firefox.lnk")
      Set colVerbs = objFolderItem.Verbs
      For Each objVerb in colVerbs
      If Replace(objVerb.name, "&", "") = "Pin to Taskbar" Then objVerb.DoIt
      Next
      End If

      This should now work with pinning Firefox 4 to the taskbar.

  • bkz81

    That did it. Thanks a lot!!!!!!

  • St4338

    I have the following programs installed and trying to use the script to pin them to the taskbar.
    “C:\Lotus\Notes\notes.exe”
    “C:\Program Files (x86)\Corel\WordPerfect Office X5\Programs\wpwin15.exe”
    C:\Schedule\Time\time.exe
    I would appreciate any help on how to modify the script to add the mentioned shortcuts to the taskbar.
    Thanks

  • strans

    Thanks for the script. It runs fine if I copy to a test PC…but when I mount an image, and copy it to c:\Users\Default\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup… then I commit the image and deploy to a PC. The script will work on the first user to log on and deletes itself. The next user does not get the icons. Any thoughts ? Am I placing it in the wrong directory?

  • sette

    What start up directory would I copy the script to once I mount a .wim file? Default user? All users? Thank you

    • Jonathan

      Try “c:\ProgramData\Microsoft\Windows\Start Menu”

      • Jonathan

        Sorry wrong reply…

        You wouldn’t want to put it in that StartUp folder because it would only run once for all users. I would suggest Default Users, which should copy it to any new user profiles’ StartUp folder when the profile is created.

        • David

          Hello Jonathan,

          I cannot find the startup folder in Default Users? Can you provide the full path?

          Thanks

        • Shan Moosa

          You want the vbs script placed under local administrator startup folder. Here is the path:
          C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup.
          Place the VBS script in there and sysprep the Image. Once image boots up, you will see that any user that logs into the machine gets the VBS script. The script will delete itself once the user is logged in for the first time (Run Once).
          It is working for me properly now.

        • David

          Hello Jonathan,

          I do not see a start up folder in default users. Does one need to be created? Also can you help verify by giving the full path?

          e.g. C:\users\default\….

          Thanks

  • itguy77

    Ok, how do I change the mozilla firefox to google chrome. I copied the seetings from Mozilla and changed the path to point where google chrome is, but it does not display..

  • http://mygtacenter.com computeruser

    Thank you so much for the tutorial, it has been incredibly insightful. As Brett mentioned for Flip 3D if you are on Windows 7.

  • burningjoe

    I am having the same issue as “strans” above where it runs for the first user to log in (in my case the administrator) and deletes itself but then any user that log’s in after that does not get the icons.

    Is there some where else this should go?

  • antneal

    I tried the vbs script above that places the icons on the taskbar and it works well if you have Microsoft Office 2010. I tried it on a box that has Office 2007 to no avail. I tried changing the “2010” referenece in the script to “2007” and that didn’t work. Not a vbs script or xml for that matter person. Can someone modify this to work with Office 2007?

    • Jonathan

      Figured out the problem with 2007. You need to add “Office” into the entries in the script when you change it for Office 2007. In 2010 it’s just “Microsoft Word 2010″ but in 2007 it’s “Microsoft Office Word 2007″.

  • Farzan Qureshi

    Will this also copy the pinned language bar or may be floating language bar. I am a network technician in a college and we have multilingual students. Kindly guide me will it also pin the language bar?

  • Pingback: Building an App-V Lab Part 1: base image creation – packageology

  • Nicholas

    I have an odd one…
    The script works great except for the explorer shortcut. It is pinned after the script runs, however when I click on it, it does not highlight the new pinned shortcut and ‘stack’ on it if multiples are opened…it opens a new one to the right of the rest of the icons (where the rest also continue to ‘stack’)

    I do have a modified ‘Windows Explorer’ shortcut however. As our org has NO use for the STUPID libraries, and am trying to point users away from them when they open explorer. So the shortcut opens to ‘Favorites’ by use of this string ; %windir%\explorer.exe shell:::{323CA680-C24D-4099-B94D-446DD2D7249E} . If I look at the properties of this pinned shortcut and click on ‘apply’ after adding/removing a space or character, the issue is resolved and the ‘stacking’ functions as it should.

    Also, if I change the shortcut string back to ‘%windir%\explorer.exe’ the problem goes away…but of course I get the libraries by default.

    ANY ideas or help are appreciated. I have also looked for a way to change (in the registry) the default location that explorer opens to, but it looks like im stuck with libraries :(.

    -Nick

  • Corey

    What would you do if the you have a 64 bit OS and need to put a 32 bit program on the taskbar? It’s not pinning half my programs because they are under 32 bit folder.

    • Jason Shirley

      Did you ever figure out how to do this?

  • Corey

    Nevermind I see how it works now

  • Dustin

    I tried to use it with my SCCM OSD TS. I created a Run Command to copy the vbs from my network share to the startup folder in the start menu. It works fine for the 1st user to login, but does not work for any other users that login. Any ides?

    • Dustin

      Answered my own question. I changed my TS to copy to C:\Users\Default\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
      and now it seems to work for any user that logs in.

  • Dustin

    Aslo.
    What would be the syntax for pinning the snipping tool to the taskbar?

  • Jason

    If anyone is still listening to this page I have a question. I am trying to run this script under a very locked down account and it seems not to work. It does under a admin account. Items under the Programs/Startup run as the logged in user context correct because that would be the issue.

    Thanks

  • Sander

    Hi,

    Is it also possible to save the tray icon configuration for a default user. So which icon which is always visual, like vnc and virusscanner an speaker icons?

    • Sander

      I mean the tray on the right. Also called notification tray.

      • http://www.theitbros.com Brian Jackson

        @Sander: It might be possible, I have never tried to change the notification tray before. Maybe someone else on here has and can chime in?

  • Jason Shirley

    Brian,

    Half of the applications I need to pin to the taskbar are 64-bit, any suggestions on modifying the script to do this? I am assuming I need to use a different environmental variable (as opposed to “strAllUsersProgramsPath”)…

    • http://theitbros.com/ Brian Jackson

      I just tested this and it doesn’t matter if it is 64-bit or not..

      Example, I just ran this…

      ‘Photoshop CS6
      If objFSO.FileExists(strAllUsersProgramsPath & “Adobe Photoshop CS6 (64 Bit).lnk”) Then
      Set objFolder = objShell.Namespace(strAllUsersProgramsPath)
      Set objFolderItem = objFolder.ParseName(“Adobe Photoshop CS6 (64 Bit).lnk”)
      Set colVerbs = objFolderItem.Verbs
      For Each objVerb in colVerbs
      If Replace(objVerb.name, “&”, “”) = “Pin to Taskbar” Then objVerb.DoIt
      Next
      End If

      That is a 64-bit program and located in the “C:Program Files” folder, unlike the other icons.

      Also above in the example, all the testing was done on 64-bit machines pinning 32-bit apps… but I just tried stripped my VBS down and ran it and pinned 64-bit Photoshop icon just fine. I am doing this on Windows 8 as test, but shouldn’t matter, should work in Windows 7.

      Hopefully that helps!

      • Jason Shirley

        First off, thanks for the website and all the scripts. Very much appreciated for oddly specific problems like this. Unfortunately, this is still not working for me. I have been using the newer version of the script. I literally copy-pasted your Photoshop example above and still no dice. Although it works fine for the pre-baked icons (Word, Excel, IE).

        What I have done so far is to remove some of the existing pins that I do not want (Windows Media Player, Outlook) and have just been trying to add more blocks of code matching your example above with the icons I want replaced. I cannot think of what could be causing this to not work as the code obviously works; I am not familiar with VBS unfortunately.

        Thanks for all the help thus far!