Monday, September 9, 2013

Programatically pin or unpin a program from the taskbar

I'll be using this as part of the revised 'Remove Google Chrome' brute force uninstaller script which will update this one: http://sccmbrokeit.blogspot.com/2013/07/uninstalling-non-admin-install-of.html

'*****************************************************************
' Name this script (Pin.vbs)
' Author: http://www.sevenforums.com/members/ronsum.html
'
' This script will programatically add/remove taskbar pinned items
'
' Use: cscript pin.vbs <full path\Name.exe> <Option>
'
' Options 0 = Un-Pin, 1 = Pin, 2 = Install (DB: I don't know what #2 does)
'
'*****************************************************************

' http://www.sevenforums.com/customization/22245-pin-taskbar-2.html

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

No comments:

Post a Comment