質問では、Old New Thingの投稿で、アプリケーションをタスクバーに固定するのを防ぐために、アプリケーションごとにレジストリ設定を設定する方法についても説明しています。
あなたがしなければならないのは、Root\Applicationsの下にあるアプリケーションのキーに「NoStartPage」の値を追加することだけです。値は空白でも、どのタイプでもかまいません。Windowsがその値を認識しただけでは、ユーザーがタスクバーで右クリックしたときにアプリを固定する機能は表示されません。
この機能に関するMicrosoftのドキュメントは次のとおりです。レジストリを使用して、アプリケーションの固定を防止します
これに対する1つの注意点は、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);
}
}
}