我正在创建一个基本软件,我想检查本地机器上的特定软件,然后选中一个框以指示软件在机器上。我经历了多个线程,发现了一些简短而又甜蜜的代码。但是,我无法将返回值或true或false与我的复选框链接起来。有人能告诉我我是否正确使用此代码?基本上我想在几个不同的参数下检查卸载中可用的项目列表(以覆盖我的32和64位操作系统的基础)在这种情况下,我正在搜索一个名为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------------------------------------------------------------------------------------------------------
答案 0 :(得分:-1)
你甚至都没有关闭。您需要调用IsApplicationInstalled
,并使用该函数的返回值。
public void checkBox1_CheckedChanged(object sender, EventArgs e)
{
checkBox1.Checked = IsApplicationInstalled(PGP);
}