I'm modifying the Chocolatey scripts to include Uninstall-ChocolateyPinnedTaskBarItem
functionality.
This works great with the following command
# WORKS
Uninstall-ChocolateyPinnedTaskBarItem "$env:ProgramFiles\Internet Explorer\iexplore.exe"
But it doesn't work with
# DOESN'T WORK
Uninstall-ChocolateyPinnedTaskBarItem "$env:SystemRoot\explorer.exe"
How can I get rid of the default pinned "Library" folder using Powershell exclusively?
Here's the Uninstall script.
function Uninstall-ChocolateyPinnedTaskBarItem {
<#
.SYNOPSIS
Removes an item from the task bar linking to the provided path.
.PARAMETER TargetFilePath
The path to the application that should be launched when clicking on the task bar icon.
.EXAMPLE
Uninstall-ChocolateyPinnedTaskBarItem "${env:ProgramFiles(x86)}\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe"
This will remove the Visual Studio task bar icon.
#>
param(
[string] $targetFilePath
)
Write-Debug "Running 'Uninstall-ChocolateyPinnedTaskBarItem' with targetFilePath:`'$targetFilePath`'";
if (test-path($targetFilePath)) {
$verb = "Unpin from Taskbar"
$path= split-path $targetFilePath
$shell=new-object -com "Shell.Application"
$folder=$shell.Namespace($path)
$item = $folder.Parsename((split-path $targetFilePath -leaf))
$itemVerb = $item.Verbs() | ? {$_.Name.Replace("&","") -eq $verb}
if($itemVerb -eq $null){
Write-Host "TaskBar verb not found for $item. It may have already been unpinned"
} else {
$itemVerb.DoIt()
}
Write-Host "`'$targetFilePath`' has been unpinned from the task bar on your desktop"
} else {
$errorMessage = "`'$targetFilePath`' does not exist, not able to unpin from task bar"
}
if($errorMessage){
Write-Error $errorMessage
throw $errorMessage
}
}
After stumbling across a similar issue, my experience leads me to believe this issue occurs in Windows 8.x only, and, IMHO, it is a bug.
tl;dr: Under the registry key [HKEY_CLASSES_ROOT\CLSID\{52205fd8-5dfb-447d-801a-d0b52f2e83e1}
, add the keys shellex\ContextMenuHandlers\{90AA3A4E-1CBA-4233-B8BB-535773D48449}
.
.reg file version:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\CLSID\{52205fd8-5dfb-447d-801a-d0b52f2e83e1}\shellex\ContextMenuHandlers\{90AA3A4E-1CBA-4233-B8BB-535773D48449}]
DISCLAIMER: [HKEY_CLASSES_ROOT\CLSID\{52205fd8-5dfb-447d-801a-d0b52f2e83e1}]
is a TrustedInstaller protected key. Use your best judgement.
Here are the steps that got me there:
To begin diagnosing the problem, I wrote this function which retrieves the pinned lnk files or, optionally, the targets of the lnk files:
function Get-UserPinnedItems([switch]$Target)
{
$userPinnedPath = "$env:APPDATA\Microsoft\Internet Explorer\Quick Launch\User Pinned\Taskbar"
$shellApp = New-Object -ComObject 'Shell.Application'
$items = $shellApp.Namespace($userPinnedPath).Items() | where { $_.IsLink }
if ($Target)
{
return $items | foreach { $_.GetLink.Target }
}
$items
}
Running the above with the -Target switch on Windows 8.1, I get back this:
PS> Get-UserPinnedItems -Target
Application : System.__ComObject
Parent : System.__ComObject
Name : File Explorer
Path : ::{52205FD8-5DFB-447D-801A-D0B52F2E83E1}
GetLink :
GetFolder :
IsLink : False
IsFolder : False
IsFileSystem : False
IsBrowsable : False
ModifyDate : 12/30/1899 12:00:00 AM
Size : 0
Type : System Folder
Notice the Path is ::{52205FD8-5DFB-447D-801A-D0B52F2E83E1}
. This is apparently a new CLSID for File Explorer for which very little information is available. Searching for this guid in the registry (or even the internet) doesn't bring back many results. On Windows 7 I get back the file system path "C:\Windows\explorer.exe" which is why I think this is a Win8-only issue.
Now, Pinning/Unpinning items to the taskbar is handled by the IStartMenuPinnedList interface which has the CLSID {90AA3A4E-1CBA-4233-B8BB-535773D48449}. Searching for this guid in the registry yields several results. Most instances occur where a particular filetype needs the Pin/Unpin functionality.
So, since the File Explorer is missing this functionality, adding the ContextMenuHandler seemed like a good idea, and sure enough, it worked like a charm, at least for me. ymmv. If it doesn't work for others, maybe it will at least provide some leads.
Aside: The OP states the pinned "Library" folder is the problem. I don't think this is entirely correct based on the fact the pinned item has the File Explorer CLSID {52205FD8-5DFB-447D-801A-D0B52F2E83E1} and not the Libraries CLSID {031E4825-7B94-4dc3-B131-E946B44C8DD5}.
While running Shell:::{031E4825-7B94-4dc3-B131-E946B44C8DD5}
always opens the Libraries folder, running Shell:::{52205FD8-5DFB-447D-801A-D0B52F2E83E1}
might open the Libraries or the This PC folder, depending on if the user has the "Show libraries" option enabled. Based on that, I would rename the post to say "File Explorer" instead of "Library". Also, I would say which OS I was using.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With