如何取消固定“库"使用 Powershell 从任务栏中获取文件夹? [英] How to unpin "Library" folder from Task Bar using Powershell?

查看:62
本文介绍了如何取消固定“库"使用 Powershell 从任务栏中获取文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在修改 Chocolatey 脚本以包含 Uninstall-ChocolateyPinnedTaskBarItem 功能.

使用以下命令效果很好

# WORKS卸载-ChocolateyPinnedTaskBarItem "$env:ProgramFiles\Internet Explorer\iexplore.exe"

但它不适用于

# 不起作用卸载-ChocolateyPinnedTaskBarItem "$env:SystemRoot\explorer.exe"

如何仅使用 Powershell 摆脱默认固定的Library"文件夹?

这是卸载脚本.

function Uninstall-ChocolateyPinnedTaskBarItem {<#.概要从任务栏中删除链接到提供的路径的项目..PARAMETER 目标文件路径单击任务栏图标时应启动的应用程序的路径..例子卸载-ChocolateyPinnedTaskBarItem "${env:ProgramFiles(x86)}\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe"这将删除 Visual Studio 任务栏图标.#>参数([字符串] $targetFilePath)编写调试使用 targetFilePath 运行'Uninstall-ChocolateyPinnedTaskBarItem':`'$targetFilePath`'";如果(测试路径($targetFilePath)){$verb = "从任务栏取消固定"$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){写主机找不到 $item 的任务栏动词.它可能已经被取消固定"} 别的 {$itemVerb.DoIt()}写入主机`'$targetFilePath`' 已从桌面任务栏中取消固定"} 别的 {$errorMessage = "`'$targetFilePath`' 不存在,无法从任务栏取消固定"}如果($错误消息){写错误 $errorMessage抛出 $errorMessage}}

解决方案

在遇到类似问题后,我的经验让我相信这个问题只发生在 Windows 8.x 中,恕我直言,这是一个错误.

tl;dr: 在注册表键 [HKEY_CLASSES_ROOT\CLSID\{52205fd8-5dfb-447d-801a-d0b52f2e83e1} 下,添加键 shellex\ContextMenuHandlers\{90AA3A4E-1CBA-4233-B8BB-535773D48449}.

.reg 文件版本:

Windows 注册表编辑器 5.00 版[HKEY_CLASSES_ROOT\CLSID\{52205fd8-5dfb-447d-801a-d0b52f2e83e1}\shellex\ContextMenuHandlers\{90AA3A4E-1CBA-4233-B8BB-535773D48449}]

免责声明:[HKEY_CLASSES_ROOT\CLSID\{52205fd8-5dfb-447d-801a-d0b52f2e83e1}] 是受 TrustedInstaller 保护的密钥.运用你最好的判断.

<小时>

以下是让我达到目标的步骤:

为了开始诊断问题,我编写了这个函数来检索固定的 lnk 文件或可选的 lnk 文件的目标:

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() |其中 { $_.IsLink }如果($目标){返回 $items |foreach { $_.GetLink.Target }}$items}

<小时>

在 Windows 8.1 上使用 -Target 开关运行上面的代码,我得到了这个:

PS>Get-UserPinnedItems -Target应用程序:System.__ComObject父级: System.__ComObject名称:文件资源管理器路径:::{52205FD8-5DFB-447D-801A-D0B52F2E83E1}获取链接      :获取文件夹:IsLink : 错误IsFolder : 错误IsFileSystem : 错误IsBrowsable : 错误修改日期 : 12/30/1899 12:00:00 AM尺寸:0类型:系统文件夹

注意路径是 ::{52205FD8-5DFB-447D-801A-D0B52F2E83E1}.这显然是文件资源管理器的新 CLSID,可用的信息很少.在注册表(甚至互联网)中搜索此 guid 不会带回很多结果.在 Windows 7 上,我取回了文件系统路径C:\Windows\explorer.exe",这就是为什么我认为这是一个仅限 Win8 的问题.

现在,将项目固定/取消固定到任务栏由 IStartMenuPinnedList 接口 其 CLSID {90AA3A4E-1CBA-4233-B8BB-535773D48449}.在注册表中搜索<​​em>这个 guid 会产生几个结果.大多数情况下,特定文件类型需要固定/取消固定功能.

因此,由于文件资源管理器缺少此功能,因此添加 ContextMenuHandler 似乎是一个好主意,而且确实如此,至少对我来说,它很有魅力.嗯.如果它对其他人不起作用,也许它至少会提供一些线索.

<小时>

旁白:OP 指出固定的库"文件夹是问题所在.我不认为这是完全正确的,因为固定项目具有文件资源管理器 CLSID {52205FD8-5DFB-447D-801A-D0B52F2E83E1} 而不是库 CLSID {031E4825-7B94-4dc3-B131-E945}DDD/p>

在运行 Shell::{031E4825-7B94-4dc3-B131-E946B44C8DD5} 时总是打开 Libraries 文件夹,运行 Shell::{52205FD8-5DFB-447D-801A-D0B52F2E83E1} 可能会打开 Libraries 或 This PC 文件夹,具体取决于用户是否启用了显示库"选项.基于此,我会将帖子重命名为文件资源管理器"而不是库".另外,我会说我使用的是哪个操作系统.

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.

这篇关于如何取消固定“库"使用 Powershell 从任务栏中获取文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆