c# - Getting a specific branch and all its values in the registry

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

1 Answer

  1. Leo- Reply

    2019-11-15

    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);
    }
    

Leave a Reply

Your email address will not be published. Required fields are marked *

You can use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>