ローカル マシンで特定のソフトウェアをチェックし、そのソフトウェアがマシン上にあることを示すボックスをチェックする基本的なソフトウェアを作成しています。複数のスレッドを調べたところ、短くて素敵なコードが見つかりました。ただし、戻り値または true または false をチェックボックスにリンクすることはできません。このコードを正しく使用しているかどうか教えてもらえますか? 基本的に、いくつかの異なるパラメーターでアンインストールで利用可能なアイテムのリストを確認したいと思います (32 ビットと 64 ビットの OS でベースをカバーするため)。この場合、Symantec Encryption と呼ばれるソフトウェアを探しています。
public static bool IsApplictionInstalled(string PGP)
{
string keyName;
// search in: CurrentUser
keyName = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
if (ExistsInSubKey(Registry.CurrentUser, keyName, "Symantec Encryption", PGP) == true)
{
return true;
}
// search in: LocalMachine_32
keyName = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
if (ExistsInSubKey(Registry.LocalMachine, keyName, "Symantec Encryption", PGP) == true)
{
return true;
}
// search in: LocalMachine_64
keyName = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall";
if (ExistsInSubKey(Registry.LocalMachine, keyName, "Symantec Encryption", PGP) == true)
{
return true;
}
return false;
}
public static bool ExistsInSubKey(RegistryKey p_root, string p_subKeyName, string p_attributeName, string PGP)
{
RegistryKey subkey;
string displayName;
using (RegistryKey key = p_root.OpenSubKey(p_subKeyName))
{
if (key != null)
{
foreach (string kn in key.GetSubKeyNames())
{
using (subkey = key.OpenSubKey(kn))
{
displayName = subkey.GetValue(p_attributeName) as string;
if (PGP.Equals(displayName, StringComparison.OrdinalIgnoreCase) == true)
{
return true;
}
}
}
}
}
return false;
}
public void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (PGP == true)
{
checkBox1.Checked = true;
}
}
// ------------------------------------------------------------------------------END------------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------END------------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------END------------------------------------------------------------------------------------------------------