#201407 - 2011-01-17 11:36 PM
UnPinning Items from 2008 R2 Taskbar
|
sb1920alk
Fresh Scripter
Registered: 2010-07-08
Posts: 15
Loc: USA
|
I have an issue while attempting to unpin items from the taskbar on 2008 R2 servers. I believe the issue is related to the kix executable running as a 32-bit process. An "identical" script in vbscript works successfully when run as a 64-bit process, but not as a 32-bit process. If I echo all of the "verbs" available, "Pin to Taskbar" is available instead of "Unpin from Taskbar." This is true for either script running in 32 bits. Only when the vbscript is run in 64 bits is the "verb" to unpin available.
Here are some examples trying to unpin powershell. The kix version does not work (due to the "verb" "Unpin from Taskbar" not being there), and if I call the vbscript from kix (making it run in 32-bits) the result is exactly the same. Running the vbscript natively works fine (in 64-bits).
In Kix:
$objApp = CreateObject("Shell.Application")
$objFSO = CreateObject("Scripting.FileSystemObject")
UnPin("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe")
;************************Start of UnPin()
Function UnPin($SourceFileNameAndPath)
;Unpins from the taskbar the program who's sources is provided
;Syntax: UnPin(<full path of shortcut's target>)
;Example: UnPin("C:\Windows\explorer.exe") ;Unpin explorer from the taskbar
$ParentFolder = Left($SourceFileNameAndPath,InStrRev($SourceFileNameAndPath,"\") - 1)
$Filename = Right($SourceFileNameAndPath,Len($SourceFileNameAndPath) - InStrRev($SourceFileNameAndPath,"\"))
If $objFSO.FileExists($SourceFileNameAndPath)
$objFolder = $objApp.Namespace($ParentFolder)
$objFolderItem = $objFolder.ParseName($Filename)
$colVerbs = $objFolderItem.Verbs
For Each $objVerb in $colVerbs
If Replace($objVerb.name,"&","") = "Unpin from Taskbar"
$objVerb.DoIt
EndIf
Next
EndIf
EndFunction;<==UnPin()
;************************End of UnPin()
In vbscript:
Public objApp, objFSO
Set objApp = CreateObject("Shell.Application")
Set objFSO = CreateObject("Scripting.FileSystemObject")
UnPin("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe")
'************************Start of UnPin()
Function UnPin(SourceFileNameAndPath)
'Unpins from the taskbar the program who's sources is provided
'Syntax: UnPin(<full path of shortcut's target>)
'Example: UnPin("C:\Windows\explorer.exe") 'Unpin explorer from the taskbar
ParentFolder = Left(SourceFileNameAndPath,InStrRev(SourceFileNameAndPath,"\") - 1)
Filename = Right(SourceFileNameAndPath,Len(SourceFileNameAndPath) - InStrRev(SourceFileNameAndPath,"\"))
If objFSO.FileExists(SourceFileNameAndPath) Then
Set objFolder = objApp.Namespace(ParentFolder)
Set objFolderItem = objFolder.ParseName(Filename)
Set colVerbs = objFolderItem.Verbs
For Each objVerb in colVerbs
If Replace(objVerb.name,"&","") = "Unpin from Taskbar" Then
objVerb.DoIt
End If
Next
End If
End Function'<==UnPin()
'************************End of UnPin()
|
|
Top
|
|
|
|
#201416 - 2011-01-18 09:27 PM
Re: UnPinning Items from 2008 R2 Taskbar
[Re: Allen]
|
sb1920alk
Fresh Scripter
Registered: 2010-07-08
Posts: 15
Loc: USA
|
...I am surprised it works at all using the path of the exe and not the link itself. That is interesting, I didn't think of using the shortcut. Using vbscript anywhere, or using kixtart on 32-bit servers, I've had no issues with the samples I posted above.
FYI, @ProductType returns "Windows Server 2008 R2 Enterprise Edition" in my case, so your syntax is ok there.
After thinking about this a little more, I like the idea of unpinning from the start menu and including .lnk in the shortcut name as options. Languages other than English are not an issue for me.
Here's what I'm using with those changes considered:
$objApp = CreateObject("Shell.Application")
$objFSO = CreateObject("Scripting.FileSystemObject")
UnPin("Windows PowerShell","Taskbar") ;Unpin PowerShell from the taskbar
;************************Start of UnPin()
Function UnPin($ShortcutName,$StartMenuOrTaskbar)
;Unpins from the start menu or taskbar the program who's shortcut name is provided
;Syntax: UnPin(<shortcut name>,<"Start Menu" | "Taskbar">)
;Example: UnPin("Windows PowerShell","Taskbar") ;Unpin PowerShell from the taskbar
If $StartMenuOrTaskbar = "Start Menu"
$ShortcutPath = %AppData% + "\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu"
$Verb = "Unpin from Start Menu"
EndIf
If $StartMenuOrTaskbar = "Taskbar"
$ShortcutPath = %AppData% + "\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar"
$Verb = "Unpin from Taskbar"
EndIf
If LCase(Right($ShortcutName,4)) <> ".lnk"
$ShortcutName = $ShortcutName + ".lnk"
EndIf
If $objFSO.FileExists($ShortcutPath + "\" + $ShortcutName)
$objFolder = $objApp.Namespace($ShortcutPath)
$objFolderItem = $objFolder.ParseName($ShortcutName)
$colVerbs = $objFolderItem.Verbs
For Each $objVerb in $colVerbs
If Replace($objVerb.name,"&","") = $Verb
$objVerb.DoIt
EndIf
Next
EndIf
EndFunction;<==UnPin()
;************************End of UnPin()
Thanks,
|
|
Top
|
|
|
|
#201417 - 2011-01-18 09:29 PM
Re: UnPinning Items from 2008 R2 Taskbar
[Re: Arend_]
|
sb1920alk
Fresh Scripter
Registered: 2010-07-08
Posts: 15
Loc: USA
|
Try switching the WOW64 redirection. This may be a good option, but I didn't have any more time to spend on this issue. It would be interesting to know why the list of verbs is different depending on the bit depth of the script process.
|
|
Top
|
|
|
|
#201418 - 2011-01-19 12:28 AM
Re: UnPinning Items from 2008 R2 Taskbar
[Re: sb1920alk]
|
sb1920alk
Fresh Scripter
Registered: 2010-07-08
Posts: 15
Loc: USA
|
I'm still having an issue trying to unpin Server Manager from the taskbar. @Error and @Serror give: -2147352567 COM exception error "DoIt" ((null) - (null)) [-2147352567/80020009] using my kix script or Allen's UDF (no issues with vbscript).
Additionally, Windows prompts: Problem with Shortcut. The item 'ServerManager.msc' that this shortcut refers to has been changed or moved, so this shortcut will no longer work properly. Do you want to delete this shortcut?
Clicking No results in no change. Clicking Yes deletes the shortcut in %AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar, but the icon pinned to the taskbar remains. Logging off and on changes the icon to a blank icon that doesn't work, but is still pinned.
|
|
Top
|
|
|
|
#203777 - 2011-11-17 05:00 PM
Re: UnPinning Items from 2008 R2 Taskbar
[Re: Allen]
|
JNK
Fresh Scripter
Registered: 2006-04-11
Posts: 33
Loc: USA
|
On a Windows 7 (32-bit) machine, when I remove an item from the Taskbar, it appears as a Recent item on the Start Menu. Is there a way to prevent this from happening? ... or more importantly, is anyone else seeing this behavior?
Edited by JNK (2011-11-17 05:01 PM)
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 1324 anonymous users online.
|
|
|