So if you want to know if an application is installed in windows you can iterate the Uninstallable apps in the registry below SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
However some application just have an executable are are not "installed".
void Main()
{
if (GetInstalledApplications().Any(a => a == "Google Chrome"))
{
//Chrome is installed
}
}
public IEnumerable<string> GetInstalledApplications()
{
string registry_key = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
using (var key = Registry.LocalMachine.OpenSubKey(registry_key))
{
foreach (var subkey_name in key.GetSubKeyNames())
{
using (var subkey = key.OpenSubKey(subkey_name))
{
yield return (string)subkey.GetValue("DisplayName");
}
}
}
}
If you want to get an installed application by default executable file name (and be able to launch it) you can iterate the values in SOFTWARE\Microsoft\Windows\CurrentVersion\App paths
void Main()
{
var appPath = GetInstalledApplications()
.Where(p => p != null && p.EndsWith("Chrome.exe", StringComparison.OrdinalIgnoreCase))
.FirstOrDefault();
if(appPath != null)
{
//Launch
}
}
public IEnumerable<string> GetInstalledApplications()
{
string registry_key = @"SOFTWARE\Microsoft\Windows\CurrentVersion\App paths";
using (var key = Registry.LocalMachine.OpenSubKey(registry_key))
{
foreach (var subkey_name in key.GetSubKeyNames())
{
using (var subkey = key.OpenSubKey(subkey_name))
{
yield return (string)subkey.GetValue("");
}
}
}
}
With this solution you could use a search drop-down with the result of GetInstalledApplications
to help the user to select the correct program instead of relying on them knowing the correct filename.