在这个问题中,Old New Thing文章还讨论了如何在每个应用程序的基础上设置一些注册表设置,以防止将应用程序固定到任务栏。
您只需在根\应用程序下将“NoStartPage”的值添加到您的应用程序的密钥。该值可以是空白的,也可以是任何类型的值,如果Windows只是看到它的存在,那么当用户在任务栏中右键单击时,它不会显示锁定应用程序的能力。
下面是来自微软对这个功能的文档:Use Registry to prevent pinning of an application
一个需要注意的情况是,在Windows 7中,由于UAC,你必须以管理员身份来更新注册表运行。我通过app.manifest做到了这一点。
找到合适的和更新的正确注册表项的代码如下(希望这不是太详细):
public static void Main(string[] args)
{
// Get Root
var root = Registry.ClassesRoot;
// Get the Applications key
var applicationsSubKey = root.OpenSubKey("Applications", true);
if (applicationsSubKey != null)
{
bool updateNoStartPageKey = false;
// Check to see if your application already has a key created in the Applications key
var appNameSubKey = applicationsSubKey.OpenSubKey("MyAppName.exe", true);
if (appNameSubKey != null)
{
// Check to see if the NoStartPage value has already been created
if (!appNameSubKey.GetValueNames().Contains("NoStartPage"))
{
updateNoStartPageKey = true;
}
}
else
{
// create key for your application in the Applications key under Root
appNameSubKey = applicationsSubKey.CreateSubKey("MyAppName.exe", RegistryKeyPermissionCheck.Default);
if (appNameSubKey != null)
{
updateNoStartPageKey = true;
}
}
if (updateNoStartPageKey)
{
// Create/update the value for NoStartPage so Windows will prevent the app from being pinned.
appNameSubKey.SetValue("NoStartPage", string.Empty, RegistryValueKind.String);
}
}
}
你有这个C#代码吗?我只是引用了Windows API代码包,所以我认为我只需要代码是您的主窗体?提前致谢。 – 2013-03-13 23:05:53