Check if an Application is Installed on Windows
In many scenarios, you may need to verify whether a specific application is installed on a Windows machine. This can be particularly useful for installation scripts or system checks. Below, I’ll walk you through a simple method to accomplish this using C#.
The Code
Here’s a straightforward implementation that checks the Windows registry to determine if an application is installed:
using System.Linq;
using Microsoft.Win32;
namespace CheckInstalledApp
{
public class InstalledApp
{
/// 08/04/2022 Mahesh Kumar Yadav. <br/>
/// <summary>
/// Check app is installed or not
/// </summary>
/// <param name="cName">Application name</param>
/// <returns></returns>
public static bool IsAppInstalled(string cName)
{
string displayName;
var registryKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
var key = Registry.LocalMachine.OpenSubKey(registryKey);
if (key != null)
{
foreach (var subKey in key.GetSubKeyNames().Select(keyName => key.OpenSubKey(keyName)))
{
displayName = subKey?.GetValue("DisplayName") as string;
if (displayName != null && displayName.Contains(cName))
{
return true;
}
}
key.Close();
}
registryKey = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall";
key = Registry.LocalMachine.OpenSubKey(registryKey);
if (key == null) return false;
{
foreach (var subKey in key.GetSubKeyNames().Select(keyName => key.OpenSubKey(keyName)))
{
displayName = subKey?.GetValue("DisplayName") as string;
if (displayName != null && displayName.Contains(cName))
{
return true;
}
}
key.Close();
}
return false;
}
}
}
How It Works
This code checks two registry paths where installed applications are typically listed:
- 64-bit applications:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
- 32-bit applications on 64-bit Windows:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall
The method IsAppInstalled
takes the application name as a parameter and returns true
if the application is found, otherwise it returns false
.
Conclusion
This method is efficient for quickly checking the presence of applications on a Windows machine. You can integrate this function into larger applications or use it as part of your system administration tools.
For the complete project and more details, check out my GitHub repository: CheckInstalledApp.
Leave a comment