Get all installed applications including paths (paths missing for some applications?)

mrw 201 Reputation points
2021-05-31T08:27:59.703+00:00

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.

Windows for IoT
Windows for IoT
A family of Microsoft operating systems designed for use in Internet of Things (IoT) devices.
382 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,236 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Daniel Zhang-MSFT 9,611 Reputation points
    2021-06-01T03:10:01.197+00:00

    Hi mrw-4494,
    As discussed in this thread, for programs installed using InstallShield or Wise, a different set of entries will be written.
    A reliable option may be to use the Windows Management Interface (WMI) to enumerate the software installed by the Windows Installer.
    Please refer to the following documents:
    Enumerating Installed Software
    Win32_Product class
    Best Regards,
    Daniel Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments