Hey, how can iterate through the registry using c#? I wish to create a structure for representing attributes of each key.
I think what you need is GetSubKeyNames()
as in this example.
private void GetSubKeys(RegistryKey SubKey)
{
foreach(string sub in SubKey.GetSubKeyNames())
{
MessageBox.Show(sub);
RegistryKey local = Registry.Users;
local = SubKey.OpenSubKey(sub,true);
GetSubKeys(local); // By recalling itself it makes sure it get all the subkey names
}
}
//This is how we call the recursive function GetSubKeys
RegistryKey OurKey = Registry.Users;
OurKey = OurKey.OpenSubKey(@".DEFAULT\test",true);
GetSubKeys(OurKey);
(NOTE: This was original copied from a tutorial http://www.csharphelp.com/2007/01/registry-ins-and-outs-using-c/, but the site now appears to be down).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With