I am creating a basic piece of software that I want to check the local machine for specific pieces of software and then check a box to indicate that the software is on the machine. I went through multiple thread and found a nice bit of code that was short and sweet. However, I am not able to link up the return value or true or false with my checkbox. Can someone tell me if I am using this code correctly? Essentially I want to check the list of items available in uninstall under a few different parameters(to cover my bases with 32 and 64 bit OS) And in this case I am searching for a piece of software called 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------------------------------------------------------------------------------------------------------