Archive for category favorites

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

Add a link to Favorites side bar (Windows 7/2008)

The Favorites side bar in Explorer is found (in Windows 7/2008) under C:\Users\%username%\Links folder. By default, this folder contains three link (.lnk) files: Desktop.lnk, Downloads.lnk and RecentPlaces.lnk.

I wrote a VB script that you can append to your network login script to create new entries in this section.




Option Explicit

‘ Create link for J drive
‘ Passing the following information to CreateLinkFile Subroutine:
‘ First: Dfs link or URL destination path
‘ Second: Link description
‘ Third: Name of link (.lnk) file
CreateLinkFile “\\Dfs\link\OrSharePath\”, “A Description”, “NameOfLnkFile.lnk”

‘ =============================
‘ Create link files for J drive
‘ =============================
Sub CreateLinkFile ( LinkTargetPath, LinkDescription, LinkFileName )

‘ Variable declarations
Dim wshShell, oShellLink, fso, strLinkFilenameAndPath

‘ Set workspace environments
Set fso = CreateObject( “Scripting.FileSystemObject” )
Set wshShell = CreateObject( “WScript.Shell” )

‘ strLinkFilenameAndPath variable holds full path where .lnk file will be saved
‘ Path is based on environment variable %USERNAME%
strLinkFilenameAndPath = “C:\Users\” & wshShell.ExpandEnvironmentStrings ( “%USERNAME%” ) & “\Links\” & LinkFileName

‘ Llink will be created only if it doesn’t already exist
If Not fso.FileExists ( strLinkFilenameAndPath ) Then

‘ .LNK file to be created in C:\Users\%USERNAME%\Links folder
Set oShellLink = wshShell.CreateShortcut( strLinkFilenameAndPath )
oShellLink.TargetPath = LinkTargetPath ‘ Absolute path to the executable, file, folder, or URL
oShellLink.Description = LinkDescription ‘ Short description, optional
oShellLink.WindowStyle = “1”             ‘ 1 = Default, 3 = Maximized, 7 = Minimized
oShellLink.Save
End If

End Sub





Leave a comment