Archive for August, 2013

Pin & Unpin Icons To The Windows 7 Taskbar

During the deployment of Windows 7, I was given the task to find out a way to pin and unpin icons to the taskbar.


Well, the process is rather easy, but it takes two steps.
  1. Find out the verbs associated with the application you want to pin/unpin to the taskbar.
  2. Execute the proper verb that will pin or unpin the application.
Note: This code isn’t mine, I modified it a bit to suit my needs

1. Let’s find the verbs

Here’s the VB code that handles that:

Const CSIDL_COMMON_PROGRAMS = &H17 
Const CSIDL_PROGRAMS = &H2 
Set objShell = CreateObject(“Shell.Application”) 
Set objScript = CreateObject( “WScript.Shell” )

REM The original code had the following line as part of it
REM Set objFolder = objShell.Namespace(“C:\Program Files\Internet Explorer”)

REM In my case, I’m pointing directly to the user path where all taskbar shortcut files are located
Set objFolder = objShell.Namespace(“C:\Users\” & objScript.ExpandEnvironmentStrings ( “%USERNAME%” ) & “\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar”)

REM I want to see a list of verbs pertaining to IE link file
Set objFolderItem = objFolder.ParseName(“Internet Explorer.lnk”) 
Set colVerbs = objFolderItem.Verbs 

For Each objVerb in colVerbs 
    Wscript.Echo objVerb 
Next
You can get verbs from .exe or .lnk files.
Here’s the output for that code (the output will change based on your computer):
cscript /nologo GetVerbs.vbs
&Open
Open file locat&ion
&Enable/Disable Digital Signature Icons
Run as &administrator
Edit with &Notepad++
Scan with System Center 2012 Endpoint Protection…
Unpin from Tas&kbar
Pin to Start Men&u
Restore previous &versions

Cu&t
&Copy
Create &shortcut
&Delete
Rena&me
P&roperties
2. Let’s pin, or unpin, to the taskbar
The code that handles pinning or unpinning to the taskbar is here:
Const CSIDL_COMMON_PROGRAMS = &H17 
Const CSIDL_PROGRAMS = &H2 
Set objShell = CreateObject(“Shell.Application”) 
Set objScriptShell = CreateObject( “WScript.Shell” )

REM Unpin Internet Explorer 64-bit from the taskbar
Set objFolder = objShell.Namespace(“C:\Users\” & objScriptShell.ExpandEnvironmentStrings ( “%USERNAME%” ) & “\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar”)

Set objFolderItem = objFolder.ParseName(“Internet Explorer (64-bit).lnk”) 
Set colVerbs = objFolderItem.Verbs

For Each objVerb in colVerbs 
    If Replace(objVerb.name, “&”, “”) = “Unpin from Taskbar” Then objVerb.DoIt 
Next

REM Pin Internet Explorer to the taskbar
Set objFolder = objShell.Namespace(“C:\Program Files (x86)\Internet Explorer”)

Set objFolderItem = objFolder.ParseName(“iexplore.exe”) 
Set colVerbs = objFolderItem.Verbs

For Each objVerb in colVerbs 
    If Replace(objVerb.name, “&”, “”) = “Pin to Taskbar” Then objVerb.DoIt 
Next
As soon as the script finishes the results are shown in the taskbar.

Leave a comment