chocolatey / choco

Chocolatey - the package manager for Windows
https://chocolatey.org
Other
10.34k stars 903 forks source link

Install-ChocolateyPinnedTaskBarItem does not pin and unpin from task bar in Windows 10 #627

Closed erotavlasme closed 1 month ago

erotavlasme commented 8 years ago

For instance

Install-ChocolateyPinnedTaskBarItem "${env:ProgramFiles(x86)}\Mozilla Thunderbird\thunderbird.exe" I get these message
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.

I modified the source code of Install-ChocolateyPinnedTaskBarItem in order to print all the operations and this is the output

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`

Am I making a mistake on calling the function?

Moreover, I would like also to unpin programs. It seems that chocolatey does not have any function to do this. I found from this thread How to unpin "Library" folder from Task Bar using Powershell? this function that is the complementary of the previous pin function.

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
}

In the same way this does not work. I know that I can use other solutions like this https://gallery.technet.microsoft.com/ScriptCenter/b66434f1-4b3f-4a94-8dc3-e406eb30b750/. However, I prefer to use all stuff from chocolatey. Do you have any suggestions?

UPDATE: We would only support this on supported operating systems which, on the client side, would be some Windows 10 and 11.

ferventcoder commented 8 years ago

@chocolatey/developers does anyone remember who worked on this one?

erotavlasme commented 8 years ago

Do you need log or debug? I can reproduce them.

ferventcoder commented 8 years ago

@erotavlas85 that is helpful - if you save it as a gist and provide the link, that would be helpful.

gep13 commented 8 years ago

That would be @mwrock

https://github.com/chocolatey/chocolatey/blame/2d61a3b0958170ade13d8ad5a09a88af9e46bb65/src/helpers/functions/Install-ChocolateyPinnedTaskBarItem.ps1

mwrock commented 8 years ago

While I dont recalll this being a problem in win 7, I have noticed that pinning is broken in win 10 and need to research why. Adding this to my to do list but might be a wek or so before I get to it.

ferventcoder commented 8 years ago

I've added this to the backlog and assigned it to you. If you get to it in time for 0.9.10, great! We can update the milestone. :)

erotavlasme commented 8 years ago

This is the output log gist link https://gist.githubusercontent.com/erotavlas85/a92ac6974212882ecf17/raw/c7b71db8ac1bccfbb10f20b11410856cb338cf9a/log.sh

erotavlasme commented 8 years ago

A possible solution to unpin all is the following `Remove-Item "$env:USERPROFILE\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar*" -recurse

Remove-Item -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Taskband" -recurse

Get-Process explorer | Stop-Process`

erotavlasme commented 8 years ago

Any news?

flcdrg commented 8 years ago

Did a bit of research on this. It turns out that according to MSDN "A small set of applications are pinned by default for new installations. Other than these, only the user can pin further applications; programmatic pinning by an application is not permitted.". This concurs with a blog post from Raymond Chen - "there is no PinToTaskBar function".

So basically any technique to achieve this is unsupported - which is probably why it stopped working in Windows 10.

I came across a comment on an issue in another repo related to the same problem where they figured out that "Pin to task bar" verb is no longer being returned.

But then after all that they apparently managed to figure out another workaround that does work in Windows 10. So if you can read this code, and figure out what it is doing, it might be possible to do the same in PowerShell

ferventcoder commented 8 years ago

The interesting bits are the DWORD at https://github.com/lordmulder/stdutils/commit/839107dc719899d31b0f67e33d76befa57ded768#diff-994c180910d9ef09478cfe0e8e854b98R723

ferventcoder commented 8 years ago

There may also be bits in those compiled DLLs they included.

teknowledgist commented 7 years ago

There is a small program to do this described here. The source code is included although I don't see a license.
More details on the how here.

Nebula83 commented 6 years ago

Any news on adding support for this in win10?

verglor commented 6 years ago

Hi, there is PowerShell snippet that works pretty well. Maybe it could be incorporated in Install-ChocolateyPinnedTaskBarItem and Install-ChocolateyShortcut -PinToTaskbar...

flcdrg commented 6 years ago

Confirming that works. Here's a tidied up version (with Close() method calls)

Param($Target)

$ValueData = (
    Get-ItemProperty("HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Windows.taskbarpin")
).ExplorerCommandHandler

$classesStarKey = (Get-Item "HKCU:\SOFTWARE\Classes").OpenSubKey("*", $true)
$shellKey = $classesStarKey.CreateSubKey("shell", $true)
$specialKey = $shellKey.CreateSubKey("{:}", $true)
$specialKey.SetValue("ExplorerCommandHandler", $ValueData)
$specialKey.Close()

$Shell = New-Object -ComObject "Shell.Application"
$Folder = $Shell.Namespace((Get-Item $Target).DirectoryName)
$Item = $Folder.ParseName((Get-Item $Target).Name)
$Item.InvokeVerb("{:}")

$shellKey.DeleteSubKey("{:}")
if ($shellKey.SubKeyCount -eq 0 -and $shellKey.ValueCount -eq 0) {
    $classesStarKey.DeleteSubKey("shell")
}

$shellKey.Close()
$classesStarKey.Close()
andymcraae1 commented 5 years ago

Hi all.

There is also tool which we use to automate the process of pinning Office 2016 and 2019 Icons to the taskbar of windows 10 (release 1809. Which is actually the most recent release). The website http://www.technosys.net/ --> Products --> Utils --> PinToTaskbar (syspin.exe).

We install office product and write in cmd (as admin): > cmd /c "c:\path_to_syspin.exe" "C:\Program Files\Microsoft Office\...\WINWORD.EXE" c:5386 and we do the same for the other office products (excel, outlook, etc..).

The tool works fine. Anyway this is not a programmatic solution which was provided just above and it not suited for this particular choco case.. but anyway this might help some people which look for an easy way to pin the ofice icons to the taskbar.

DavidNgoDev commented 5 years ago

Is it me or is this not working for Windows 10 1903?

flcdrg commented 5 years ago

@DavidNgoDev which thing in particular are you referring to as not working?

DavidNgoDev commented 5 years ago

@DavidNgoDev which thing in particular are you referring to as not working?

Install-ChocolateyShortcut : The term 'Install-ChocolateyShortcut' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

flcdrg commented 5 years ago

Install-ChocolateyShortcut is a Chocolatey function. I don't believe you can call those by default from a Boxstarter script. This issue is about Install-ChocolateyPinnedTaskBarItem

teknowledgist commented 5 years ago

@flcdrg The code you posted works fine for admins (which is how most packages install anyway), but I didn't get it to work for non-admins.

Here is some alternative code that works for both.. I think it only works for applications that are already in the Start Menu programs list, although it's easy enough to create an icon in %APPDATA%\Microsoft\Windows\Start Menu first.

Edit: Oops! This is for pinning to the Start Menu which I should have noticed is not the point of this issue. It does not appear to work for the taskbar. (At one time, the code for pinning to Start and pinning to taskbar were nearly identical. MS blocked Start menu pinning via code, and this is the first time since that I have seen it work.) Sorry for the distraction.

flcdrg commented 5 years ago

@teknowledgist That script talks about pinning to the start menu - does it pin to the task bar though?

corbob commented 1 month ago

Due to the constant moving target provided by Microsoft, we have opted to deprecate the Install-ChocolateyPinnedTaskBarItem function in the next release of Chocolatey CLI (#3520) to be removed with 3.0.0 (#3521).

As such I will close this issue.