I am trying to get all installed applications including paths. Looks like applications are listed correctly but for some applications paths are missing for some reason. Why so and how to get path of each installed application as well?
Here is main method for retrieving a list:
private static List<InstalledApp> GetInstalledApplication(RegistryKey regKey, string registryKey)
{
List<InstalledApp> list = new List<InstalledApp>();
using (Microsoft.Win32.RegistryKey key = regKey.OpenSubKey(registryKey))
{
if (key != null)
{
foreach (string name in key.GetSubKeyNames())
{
using (RegistryKey subkey = key.OpenSubKey(name))
{
string displayName = (string)subkey.GetValue("DisplayName");
string installLocation = (string)subkey.GetValue("InstallLocation");
if (!string.IsNullOrEmpty(displayName)) // && !string.IsNullOrEmpty(installLocation)
{
list.Add(new InstalledApp()
{
DisplayName = displayName.Trim(),
InstallationLocation = installLocation
});
}
}
}
}
}
return list;
}
Then I am combining all together here:
private static List<InstalledApp> GetFullListInstalledApplication()
{
IEnumerable<InstalledApp> finalList = new List<InstalledApp>();
string registry_key_32 = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
string registry_key_64 = @"SOFTWARE\WoW6432Node\Microsoft\Windows\CurrentVersion\Uninstall";
List<InstalledApp> win32AppsCU = GetInstalledApplication(Registry.CurrentUser, registry_key_32);
List<InstalledApp> win32AppsLM = GetInstalledApplication(Registry.LocalMachine, registry_key_32);
List<InstalledApp> win64AppsCU = GetInstalledApplication(Registry.CurrentUser, registry_key_64);
List<InstalledApp> win64AppsLM = GetInstalledApplication(Registry.LocalMachine, registry_key_64);
finalList = win32AppsCU.Concat(win32AppsLM).Concat(win64AppsCU).Concat(win64AppsLM);
finalList = finalList.GroupBy(d => d.DisplayName).Select(d => d.First());
return finalList.ToList();
}
InstalledApp is class with two string properties.