1

I want to be able to get all the value pairs under a location in the registry, like:

 RegistryKey printerkey =
                settingsRegKey.OpenSubKey("\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Print\\Printers\\DevModes2\\Settings");

I can select Registry.LocalSystem, etc, but how do I then get to a specific branch (like above)?

Thanks

Twelve47
  • 3,924
  • 3
  • 22
  • 29
blade44
  • 447
  • 1
  • 4
  • 7

1 Answers1

9
Dictionary<string, object> keyValuePairs;
using (var settingsRegKey = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows NT\\CurrentVersion\\Print\\Printers\\DevModes2\\Settings"))
{
       var valueNames = settingsRegKey.GetValueNames();
       keyValuePairs = valueNames.ToDictionary(name => name, settingsRegKey.GetValue);
}
Bob G
  • 1,226
  • 2
  • 16
  • 24
  • 1
    You should also check if the settingRegKey is not null. The key might not exists. If the settingRegKey is not null then you can call GetValueNames. – Alexandru Dicu Oct 09 '12 at 11:01
  • If you're on 64bit machine, use this approach to open `Registry.LocalMachine`: http://stackoverflow.com/a/13190185/244353 – Mrchief Mar 20 '14 at 18:29