Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
erotavlasme opened this issue Feb 11, 2016 · 24 comments

Comments

@erotavlasme
Copy link

erotavlasme commented Feb 11, 2016

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
Copy link
Member

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

@erotavlasme
Copy link
Author

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

@ferventcoder
Copy link
Member

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

@mwrock
Copy link
Member

mwrock commented Feb 11, 2016

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 ferventcoder added this to the 0.9.10.x milestone Feb 11, 2016
@ferventcoder
Copy link
Member

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
Copy link
Author

@erotavlasme
Copy link
Author

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
Copy link
Author

Any news?

@flcdrg
Copy link
Member

flcdrg commented Apr 9, 2016

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
Copy link
Member

The interesting bits are the DWORD at lordmulder/stdutils@839107d#diff-994c180910d9ef09478cfe0e8e854b98R723

@ferventcoder
Copy link
Member

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

dmce added a commit to dmce/windows-dev-env that referenced this issue Dec 8, 2016
@teknowledgist
Copy link

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
Copy link

Nebula83 commented Jul 3, 2018

Any news on adding support for this in win10?

@verglor
Copy link

verglor commented Oct 25, 2018

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

@flcdrg
Copy link
Member

flcdrg commented Oct 26, 2018

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
Copy link

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
Copy link

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

@flcdrg
Copy link
Member

flcdrg commented Jun 3, 2019

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

@DavidNgoDev
Copy link

@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
Copy link
Member

flcdrg commented Jun 6, 2019

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
Copy link

teknowledgist commented Jun 12, 2019

@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
Copy link
Member

flcdrg commented Jun 13, 2019

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

@pauby pauby changed the title Chocolatey: pin and unpin programs from task bar does not work on Windows 10 and Windows 7 Install-ChocolateyPinnedTaskBarItem does not pin and unpin from task bar in Windows 10 Aug 28, 2024
@corbob
Copy link
Member

corbob commented Sep 26, 2024

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.

@corbob corbob closed this as not planned Won't fix, can't repro, duplicate, stale Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests