我正在修改Chocolatey脚本以包含Uninstall-ChocolateyPinnedTaskBarItem
功能。
这适用于以下命令
# WORKS
Uninstall-ChocolateyPinnedTaskBarItem "$env:ProgramFiles\Internet Explorer\iexplore.exe"
但它不适用于
# DOESN'T WORK
Uninstall-ChocolateyPinnedTaskBarItem "$env:SystemRoot\explorer.exe"
如何仅使用 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
}
}