【发布时间】: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
【问题讨论】:
标签: c# wpf windows-10 windows-api-code-pack