Question

I have a registry key location that appears as the following:

enter image description here

I'm looking for C# code that will allow me to enumerate all REG_SZ values in HKEY_LOCAL_MACHINE\SOFTWARE\Test\Windows Update\Exceptions so that I can add them to a list. I have found examples of how to read a specific value (the RegistryKey.GetValue method) when you know the explicit path, but in this case I will need to read in all values under the "Exceptions" key without knowing what the value names will be.

Was it helpful?

Solution

RegistryKey.GetValueNames() should give you the list you are looking for. You can then iterate through the returned names, and call RegistryKey.GetValue(string) to get each's value. For example:

foreach(valueName in exceptions.GetValueNames())
    myList.Add(String.Format("{0} is {1}", valueName, exceptions.GetValue(valueName)));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top