Windows Chocolate和powershell:从任务栏和文件关联中锁定和取消锁定程序

Windows Chocolate和powershell:从任务栏和文件关联中锁定和取消锁定程序,windows,powershell,chocolatey,taskbar,Windows,Powershell,Chocolatey,Taskbar,我想用巧克力从任务栏上固定和取消固定程序。我知道我可以使用helper函数安装ChocolateTynnedtaskbaritem来锁定程序 比如说 Install chocolateypinedtaskbaritem“${env:ProgramFiles(x86)}\Mozilla Thunderbird\Thunderbird.exe” 我收到这些信息 未找到系统的任务栏谓词。\u。它可能已经被钉住了 “C:\Program Files(x86)\Mozilla Thunderbird\Th

我想用巧克力从任务栏上固定和取消固定程序。我知道我可以使用helper函数
安装ChocolateTynnedtaskbaritem
来锁定程序

比如说
Install chocolateypinedtaskbaritem“${env:ProgramFiles(x86)}\Mozilla Thunderbird\Thunderbird.exe”
我收到这些信息

未找到系统的任务栏谓词。\u。它可能已经被钉住了 “C:\Program Files(x86)\Mozilla Thunderbird\Thunderbird.exe”已固定到桌面上的任务栏,但Thunderbird未固定,桌面上也没有图标。

我修改了Install ChocolateTynnedtaskbaritem的源代码,以便打印所有操作,这就是输出

Split-path C:\Program Files\Mozilla Firefox
Folder System.__ComObject
Item System.__ComObject
ItemVerb
TaskBar verb not found for System.__ComObject. It may have already been pinned
'C:\Program Files\Mozilla Firefox\firefox.exe' has been pinned to the task bar on your desktop
Split-path C:\Program Files (x86)\Mozilla Thunderbird
Folder System.__ComObject
Item System.__ComObject
ItemVerb
TaskBar verb not found for System.__ComObject.
'C:\Program Files (x86)\Mozilla Thunderbird\thunderbird.exe' has been pinned to the task bar on your desktop`
调用函数时是否出错

此外,我还想取消pin程序。看来巧克力并没有任何作用。我从这个线程中发现了这个函数,它是先前pin函数的补充

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
}
函数卸载ChocolateTynnedtaskbaritem{
param(
[字符串]$targetFilePath
)
使用targetFilePath:“$targetFilePath`”编写调试“正在运行‘卸载ChocolateTynnedtaskBarItem’”;
if(测试路径($targetFilePath)){
$verb=“从任务栏取消绑定”
$path=拆分路径$targetFilePath
$shell=新对象-com“shell.Application”
$folder=$shell.Namespace($path)
$item=$folder.Parsename((拆分路径$targetFilePath-leaf))
$itemVerb=$item.Verbs()|?{$\.Name.Replace(&,“”)-eq$verb}
如果($itemVerb-eq$null){
Write Host“找不到$item的任务栏谓词。它可能已被取消固定”
}否则{
$itemVerb.DoIt()
} 
写入主机“`$targetFilePath`”已从桌面上的任务栏取消固定
}否则{
$errorMessage=“`$targetFilePath`'不存在,无法从任务栏取消绑定”
}
如果($errorMessage){
写入错误$errorMessage
抛出$errorMessage
}
同样,这也不起作用。 我知道我可以使用其他类似的解决方案。但是,我更喜欢使用巧克力中的所有东西。 你有什么建议吗

编辑: 在Windows 7和10上,甚至某些文件关联也不起作用。 以下内容适用于windows 7,但不适用于windows 10

Install chocolatefileassociation.html”“$ProgramsPath\Mozilla Firefox\Firefox.exe”
以下内容仅适用于windows 7,并且仅适用于.ps1文件扩展名

Install chocolateFileAssociation.txt”“${env:ProgramFiles(x86)}\Notepad++\Notepad++.exe”
安装ChocolateFileAssociation.ps1”“${env:ProgramFiles(x86)}\Notepad++\Notepad++.exe”

以下内容适用于windows 7和windows 10

Install chocolateFileAssociation.rar”“$ProgramsPath\7-Zip\7zFM.exe”
安装ChocolateFileAssociation.zip“$ProgramsPath\7-zip\7zFM.exe”

安装ChocolateFileAssociation.7z“$ProgramsPath\7-Zip\7zFM.exe”

这其中的许多问题看起来需要解决-您似乎发现了一些错误,并具有添加取消固定任务栏支持的功能


您是否介意在项目中创建所有这些问题,以便对其进行分类和处理?谢谢!

哪个版本的windows?我尝试了windows 7 Ultimate 64位和windows 10 Pro 64位。好的,谢谢您的回复。我将报告这些问题,希望能快速修复:)