Using WindowsAPICodePack.Shell
I am trying to prevent users from pinning a WPF application to the Start menu and Taskbar. I'm doing this on a Windows 10 machine.
I've tried two approaches and both prevent pinning to the Taskbar but still can pin to the Start Menu.
Option 1
public void PreventPin()
{
Window parentWindow = Window.GetWindow(ShellWindow);
string appID = "UI";
Guid propGuid = new Guid("{9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3}");
PropertyKey idProperty = new PropertyKey(propGuid, 5); // System.AppUserModel.ID
PropertyKey preventTaskbarPinning = new PropertyKey(propGuid, 9); // System.AppUserModel.PreventPinning
PropertyKey preventStartPinning = new PropertyKey(propGuid, 12); // System.AppUserModel.PreventPinning
//Important: Set PreventPinning before ID
WindowProperties.SetWindowProperty(parentWindow, preventTaskbarPinning, "True");
WindowProperties.SetWindowProperty(parentWindow, preventStartPinning, "2");
WindowProperties.SetWindowProperty(parentWindow, idProperty, appID);
}
Option 2 - also have UI present in the Registry at HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileAssociation\NoStartPageAppUserModelIDs\ with a entry of "UI"
public void PreventPin()
{
Window parentWindow = Window.GetWindow(ShellWindow);
string appID = "UI";
Guid propGuid = new Guid("{9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3}");
PropertyKey idProperty = new PropertyKey(propGuid, 5); // System.AppUserModel.ID
WindowProperties.SetWindowProperty(parentWindow, idProperty, appID);
}
Any ideas what I'm doing wrong?
Some references:
https://learn.microsoft.com/en-us/previous-versions//jj553605(v=vs.85)?redirectedfrom=MSDN
Control path to pinned exe in Windows taskbar and start menu