Chocolatey 和 powershell:从任务栏和文件关联中固定和取消固定程序

Posted

技术标签:

【中文标题】Chocolatey 和 powershell:从任务栏和文件关联中固定和取消固定程序【英文标题】:Chocolatey and powershell: pin and unpin programs from task bar and file associations 【发布时间】:2016-01-18 18:01:32 【问题描述】:

我想使用巧克力从任务栏中固定和取消固定程序。我知道我可以使用辅助函数Install-ChocolateyPinnedTaskBarItem 来固定程序。

例如 Install-ChocolateyPinnedTaskBarItem "$env:ProgramFiles(x86)\Mozilla Thunderbird\thunderbird.exe" 我收到这些消息

TaskBar verb not found for System.__ComObject. It may have already been pinned 'C:\Program Files (x86)\Mozilla Thunderbird\thunderbird.exe' has been pinned to the task bar on your desktop however thunderbird is not pinned and there is no icon on the desktop.

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

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`

我在调用函数时犯了错误吗?

此外,我还想取消固定程序。巧克力似乎没有任何功能可以做到这一点。我从这个线程How to unpin "Library" folder from Task Bar using Powershell?发现这个函数是前面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

同样,这不起作用。 我知道我可以使用像 https://gallery.technet.microsoft.com/ScriptCenter/b66434f1-4b3f-4a94-8dc3-e406eb30b750/ 这样的其他解决方案。但是,我更喜欢使用巧克力中的所有东西。 你有什么建议吗?

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

Install-ChocolateyFileAssociation ".html" "$ProgramsPath\Mozilla Firefox\firefox.exe" 以下仅适用于 Windows 7 且仅适用于 .ps1 文件扩展名

Install-ChocolateyFileAssociation ".txt" "$env:ProgramFiles(x86)\Notepad++\notepad++.exe" Install-ChocolateyFileAssociation ".ps1" "$env:ProgramFiles(x86)\Notepad++\notepad++.exe"

以下适用于 Windows 7 和 Windows 10

Install-ChocolateyFileAssociation ".rar" "$ProgramsPath\7-Zip\7zFM.exe" Install-ChocolateyFileAssociation ".zip" "$ProgramsPath\7-Zip\7zFM.exe" Install-ChocolateyFileAssociation ".7z" "$ProgramsPath\7-Zip\7zFM.exe"

【问题讨论】:

哪个版本的 windows? 我尝试了 Windows 7 Ultimate 64 位和 Windows 10 Pro 64 位。 【参考方案1】:

其中大部分内容看起来需要作为问题提交给https://github.com/chocolatey/choco/issues - 看来您已经发现了一些错误并具有添加取消固定任务栏支持的功能。

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

【讨论】:

好的,谢谢您的回复。我会报告这些问题,我希望能快速修复:)

以上是关于Chocolatey 和 powershell:从任务栏和文件关联中固定和取消固定程序的主要内容,如果未能解决你的问题,请参考以下文章

powershell 用于使用Chocolatey安装开发机器的PowerShell脚本。

powershell 用于使用Chocolatey安装开发机器的PowerShell脚本。

powershell 用于使用Chocolatey安装开发机器的PowerShell脚本。

Chocolatey 简介(软件自动化管理工具)

powershell BoxStarter使用Chocolatey Install Scripts

powershell install_chocolatey.ps1