Healthcare IT Blog

A place to blog about Healthcare Informatics Software Development Implementations

image

C# code snippet - How to check if program is installed?

By Technical Team Technosoft |22 February 2015

This function will search the given program display name in the registry and returns true if it is installed.

See the name of the program in Add/Remove Programs list.

public static bool IsProgramInstalled(string displayName, bool x86Platform)
{
string uninstallKey = string.Empty;

if (x86Platform)
{
uninstallKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
}

else
{
uninstallKey = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall";
}

using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(uninstallKey))
{

foreach (string skName in rk.GetSubKeyNames())
{
using (RegistryKey sk = rk.OpenSubKey(skName))
{
if (sk.GetValue("DisplayName") != null && sk.GetValue("DisplayName").ToString().ToUpper().Equals(displayName.ToUpper()))
{
return true; //exists
}

}
}
}

return false;
}  public static bool Contains(string inputString, string strToSearch)
{
return Regex.IsMatch(inputString, strToSearch);