我正在修改Chocolatey脚本以包含Uninstall-ChocolateyPinnedTaskBarItem功能.
这适用于以下命令
# WORKS
Uninstall-ChocolateyPinnedTaskBarItem "$env:ProgramFiles\Internet Explorer\iexplore.exe"
Run Code Online (Sandbox Code Playgroud)
但它不起作用
# DOESN'T WORK
Uninstall-ChocolateyPinnedTaskBarItem "$env:SystemRoot\explorer.exe"
Run Code Online (Sandbox Code Playgroud)
如何使用Powershell专门删除默认固定的"Library"文件夹?
这是卸载脚本.
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
}
}
Run Code Online (Sandbox Code Playgroud)
在偶然发现类似的问题后,我的经验让我相信这个问题仅发生在 Windows 8.x 中,恕我直言,这是一个错误。
tl;dr:在注册表项下[HKEY_CLASSES_ROOT\CLSID\{52205fd8-5dfb-447d-801a-d0b52f2e83e1},添加注册表项shellex\ContextMenuHandlers\{90AA3A4E-1CBA-4233-B8BB-535773D48449}。
.reg文件版本:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\CLSID\{52205fd8-5dfb-447d-801a-d0b52f2e83e1}\shellex\ContextMenuHandlers\{90AA3A4E-1CBA-4233-B8BB-535773D48449}]
Run Code Online (Sandbox Code Playgroud)
免责声明:[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() | where { $_.IsLink }
if ($Target)
{
return $items | foreach { $_.GetLink.Target }
}
$items
}
Run Code Online (Sandbox Code Playgroud)
在 Windows 8.1 上使用 -Target 开关运行上述命令,我得到以下结果:
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
Run Code Online (Sandbox Code Playgroud)
请注意,路径是::{52205FD8-5DFB-447D-801A-D0B52F2E83E1}。这显然是文件资源管理器的新 CLSID,但可用信息很少。在注册表(甚至互联网)中搜索该 guid 不会返回很多结果。在 Windows 7 上,我找回文件系统路径“C:\Windows\explorer.exe”,这就是为什么我认为这是 Win8 独有的问题。
现在,将项目固定/取消固定到任务栏由IStartMenuPinnedList接口处理,该接口的 CLSID 为 {90AA3A4E-1CBA-4233-B8BB-535773D48449}。在注册表中搜索该guid 会产生几个结果。大多数情况下,特定文件类型需要固定/取消固定功能。
因此,由于文件资源管理器缺少此功能,因此添加 ContextMenuHandler 似乎是一个好主意,而且果然,它就像一个魅力,至少对我来说是这样。ymmv。如果它对其他人不起作用,也许它至少会提供一些线索。
旁白:OP 指出固定的“Library”文件夹是问题所在。我认为这并不完全正确,因为固定项目具有文件资源管理器 CLSID {52205FD8-5DFB-447D-801A-D0B52F2E83E1} 而不是库 CLSID {031E4825-7B94-4dc3-B131-E946B44C8DD5}。
虽然运行时Shell:::{031E4825-7B94-4dc3-B131-E946B44C8DD5}始终会打开“库”文件夹,但运行时Shell:::{52205FD8-5DFB-447D-801A-D0B52F2E83E1}可能会打开“库”或“此电脑”文件夹,具体取决于用户是否启用了“显示库”选项。基于此,我会将帖子重命名为“文件资源管理器”而不是“库”。另外,我会说我正在使用哪个操作系统。
| 归档时间: |
|
| 查看次数: |
1996 次 |
| 最近记录: |