【问题标题】:How to prevent Start Menu Pinning in WPF App如何防止 WPF 应用程序中的开始菜单固定
【发布时间】:2021-11-14 11:41:32
【问题描述】:

使用WindowsAPICodePack.Shell 我试图阻止用户将 WPF 应用程序固定到“开始”菜单和任务栏。我在 Windows 10 机器上执行此操作。

我尝试了两种方法,都可以阻止固定到任务栏,但仍然可以固定到开始菜单。

选项 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);
    }

选项 2 - 在 HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileAssociation\NoStartPageAppUserModelIDs\ 的注册表中也存在 UI,并带有“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);
    }

任何想法我做错了什么?

一些参考资料:

https://docs.microsoft.com/en-us/previous-versions//jj553605(v=vs.85)?redirectedfrom=MSDN

Control path to pinned exe in Windows taskbar and start menu

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

【问题讨论】:

    标签: c# wpf windows-10 windows-api-code-pack


    【解决方案1】:

    我有个提议,设置你的主窗口,防止用户使用windows上的其他资源:

    WindowStyle="None" WindowState="Maximized"
    

    这不是仅显示您的应用的最佳解决方案。

    【讨论】:

    • 我不确定这有什么帮助。用户肯定需要使用机器上的其他应用程序。我只需要他们阻止他们选择“Pin to Start”
    猜你喜欢
    • 1970-01-01
    • 2021-09-22
    • 2012-04-11
    • 1970-01-01
    • 2011-09-16
    • 2021-07-06
    • 1970-01-01
    • 1970-01-01
    • 2015-09-13
    相关资源
    最近更新 更多