在這個問題中,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