2

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

https://learn.microsoft.com/en-us/windows/win32/shell/how-to-exclude-items-from-taskbar-pinning-and-recent-frequent-lists

Ciaran Martin
  • 578
  • 4
  • 12

1 Answers1

-1

I have a proposition, set your main window to prevent user from using other resources on windows:

WindowStyle="None" WindowState="Maximized"

It is not the best solution it will display only your app.

YacineSM
  • 81
  • 3
  • I'm not sure how this helps. Users will definitely need to user other apps on the machine. I just need them to prevent them from selecting "Pin to Start" – Ciaran Martin Sep 21 '21 at 14:53