windows - Chocolatey 和 powershell : pin and unpin programs from task bar and file associations

标签 windows powershell chocolatey taskbar

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

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

找不到 System.__ComObject 的 TaskBar 动词。它可能已经固定 “C:\Program Files (x86)\Mozilla Thunderbird\thunderbird.exe”已固定到桌面的任务栏,但 thunderbird 未固定且桌面上没有图标。

我修改了 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?此功能是对先前引脚功能的补充。

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 文件扩展名

安装-ChocolateyFileAssociation ".txt""${env:ProgramFiles(x86)}\Notepad++\notepad++.exe" 安装-ChocolateyFileAssociation ".ps1""${env:ProgramFiles(x86)}\Notepad++\notepad++.exe"

以下适用于 windows 7 和 windows 10

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

最佳答案

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

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

关于windows - Chocolatey 和 powershell : pin and unpin programs from task bar and file associations,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34861159/

相关文章:

无法将全局变量从 dll 导入到应用程序中?

powershell - 通过 Powershell 或 CLI 配置 Azure Web 应用程序部署槽

powershell - 如何在 VSTS 中的托管代理上运行或安装工具

azure - Powershell 任务中设置 $var 'The term ' keyVaultName' 时出错,未被识别为 cmdlet 的名称”

PowerShell 脚本自行打开浏览器

powershell - 巧克力不工作

meteor - 安装巧克力时出错。我应该怎么办?

c - 通过随机重命名覆盖 Windows 中的文件失败

c# - 是否可以识别exe是否是Windows服务?

c - 从键盘获取输入,无需等待输入