0

I try to access certain Registry subkeys, but I can't see certain subkeys.

I run a 32-bit application in a 64-bit edition of Windows. I saw this question, but I don't know where to put the following line:

RegistryBase = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);

In my code:

string registry_key = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
using(Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(registry_key))
{
    foreach(string subkey_name in key.GetSubKeyNames())
    {
        using(RegistryKey subkey = key.OpenSubKey(subkey_name))
        {
            if(subkey!=null)
                   Console.WriteLine(subkey.GetValue("DisplayName"));
        }
    }
}
Community
  • 1
  • 1

1 Answers1

0

Something like this should work:

string registry_key = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
using(Microsoft.Win32.RegistryKey key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64).OpenSubKey(registry_key))
{
    foreach(string subkey_name in key.GetSubKeyNames())
    {
        using(RegistryKey subkey = key.OpenSubKey(subkey_name))
        {
            if(subkey!=null)
                   Console.WriteLine(subkey.GetValue("DisplayName"));
        }
    }
}
Harry Johnston
  • 35,639
  • 6
  • 68
  • 158