-1

I have tried this approach to get the list of add/remove programs and it still does not give the exact list

Look in at the registry in 3 places

installedSoftware.AddRange(GetInstalledSoftware(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"));
installedSoftware.AddRange(GetInstalledSoftware(@"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"));
installedSoftware.AddRange(GetInstalledSoftware(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"));

Code:

private List<string> GetInstalledSoftware(string regKey)
{
    var installedSoftware = new List<string>();

    using (RegistryKey key = Registry.LocalMachine.OpenSubKey(regKey))
    {
        if (key != null)
        {
            foreach (string subkey_name in key.GetSubKeyNames())
            {
                using (RegistryKey subkey = key.OpenSubKey(subkey_name))
                {
                    object displayName = subkey.GetValue(ToolResources.DisplayName);

                    if (displayName != null)
                    {
                        installedSoftware.Add(displayName.ToString());
                    }
                }
           }
       }
    }

    return installedSoftware;
}

This is a 4.0 solution but will NOT work in 3.5

C#: How to get installing programs exactly like in control panel programs and features?

What am I missing?

Community
  • 1
  • 1
nlstack01
  • 789
  • 2
  • 7
  • 30

1 Answers1

0

This is due to the autoquery of 32/64 bit keys. If you have .net 4 you can force 32 bit applications to query for x64 keys by using the RegistryView.Registry64 attribute

var hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64))
using (var key = hklm.OpenSubKey( key ))
{....}

if you want to use the same functionality in .net 3.5 you will have to write quiet some code. See this article for a solution: Query Registry With .net 3.5

"This can also be done in .NET 3.5 and prior but it is not easy. We have to do use a DLLImport and use RegOpenKeyEx, RegCloseKey, and RegQueryValueEx. Here are some examples."

Marc Wittmann
  • 2,286
  • 2
  • 28
  • 41