I want my application to be pinned to the taskbar when the user press the minimizing button of the form but I have no Idea how to do it or if it is possible my OS is windows 10... Thanks for your help
-
3[ShowInTaskBar property](https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.form.showintaskbar?view=netframework-4.8) – John Wu Jul 23 '19 at 08:04
-
It's too broad. Which technology are you using, WinForms/WPF/UWP? – Pavel Anikhouski Jul 23 '19 at 08:04
-
@PavelAnikhouski I am using WinForms – Ale61268967 Jul 23 '19 at 08:07
-
You have to make changes to the default form settings to stop it showing in the taskbar. Without seeing any code it's difficult to offer any help. – Reinstate Monica Cellio Jul 23 '19 at 08:08
1 Answers
When you minimize your window, by default, it will be minimized in the taskbar. Unless you have set it to not show there.
If that is what you want, you have to do nothing. As per pinning it you should not do it.
Don't ask for support for pinning, here is why
Microsoft goes in great length to prevent applications altering user preferences. Why? Because otherwise, every application would do it. Giving access to user preferences via API means developers start exploiting it. It means applications fighting for screen space. You install compnay A product and it unpins company B product.
If such API existed, imagine how easy would it be to write a "joke program" that replaces all your pins. Yes, that is malware.
And no, an API for only the calling executable is not viable, it would mean that somewhere deep in the operating system the function call to do it for any executable exists. And then somebody finds it and calls it directly. Besides, it has been a big trouble for Microsoft to decouple the shell as it is.
Instead explorer handles it.
Further reading Why is there no programmatic access to the Start menu pin list?.
Thus, the answer is "Please don't do it".
But that other app did it...
Alright, some application do manage to pin, how do they do it?
Regardless of what it is I can tell you:
- It is a bad practice.
- It is not guaranteed to work, much less in the next Windows update.
One way is to mimic user input. It is hard to consider all cases (what if the taskbar is hidden, what if it is not in the usual place, what if explorer is not running, etc.), but you can imagine setting the pointer position and sending keys.
Another way would be to write directly to the list. Where is it? You might have found out that the pinned items are at:
%AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar
And they are regular, good old, shortcuts. And you could add your own. And it would not work.
The pinned items are actually controlled by group policy. Apparently the shortcuts are a fallback. You would need to mess with Windows registry. See How to manage Windows Taskbar Items pinning using Group Policy. I guess we want Favorites
and FavoritesResolve
from HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Taskband
. Well, it is not a plain list, it is binary. My best guess is that it is a dump of the shortcut files in some packing format, good luck.
I'm not figuring that out for you. Besides, I bet people find it here, start exploiting it, and then Microsoft change it, then it does not work.
Apparently there was at some point a programmatic way to do it Pin Items to the Start Menu or Windows 7 Taskbar via Script . The idea was to get a shell object from the shortcut and run a "Pin to Tas&kbar" verb on it. Script provided in the linked article. I'm not going into detail on it because.... it does no longer work:
it is an intentional change in behavior by the Windows client team. I believe the Windows team is aware of the concerns, but you can provide feedback via the Windows 10 Feedback app.
You can also read there:
The items that are pinned to the Start menu or taskbar is a user preference. Applications should not be overriding the user’s preferences. In the long term, programmaticaly pinning items to the taskbar or Start menu in Windows 10 will not be supported. Only the user will be able to pin items.
Apparently it could work by running the application with administrator privileges, can't confirm. Regardless, as you can see, there are no guarantees.
See also: How did that program manage to pin itself to my taskbar when I installed it?.
If you really have to do it, as Raymond Chen would put it, I hope you get your bonus.

- 31,890
- 5
- 57
- 86
-
I agree but there are times it would be useful. Say using a non persistent virtual desktop pool with folder redirection minus appdata as that would defeat the purpose of non persist pool. It'd be nice to programmatically set customizations for users since app data isn't being roamed. So instead enterprises use mandatory profiles and what do you know put every dang shortcut etc to appease the masses in the mandatory profile and it ends up looking like a CF anyway lol. – JMIII Aug 27 '20 at 12:28
-
Usually pinning is an undesired behavior. That's why I was looking for API to remove items which are automatically pinned on my work PC at every start. This is a use case for such API which I approve :) – Marcin Śmiałek Dec 03 '20 at 11:45