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.

有帮助吗?

解决方案

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)));
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top