Loop through all registry values in a RegistryKey (recursion)


i need looping recursively through registrykey (in case, it's registry.localmachine) , values present in registrykey (again, in test example it's registry.localmachine). well, @ least 1 available accessed , wouldn't throw security exceptions.

have no idea how proceed this. best have (doesn't work):

             public void outputregkey(registrykey key)
            {
                  foreach (string keyname in key.getsubkeynames())
                 {
                     try
                    {
                         using (registrykey key2 = key.opensubkey(keyname))
                         {
                              foreach (string valuename in key.getvaluenames())
                             {
                                  combobox1.items.add(valuename);
                                  outputregkey(key2);
                             }
                          }
                    }
                    catch
                   {

                   }
              }
        }

p.s.: not homework assigned do; it's want learn do, attempts have ended in failure.

hi laura,

you should add registry.users field that contains information default user configuration. field reads windows registry base key hkey_users.

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); // recalling itselfit makes sure subkey names     } }  //this how call recursive function getsubkeys registrykey ourkey = registry.users; ourkey = ourkey.opensubkey(@".default\test",true); getsubkeys(ourkey);

best regards,

kristin


we trying better understand customer views on social support experience, participation in interview project appreciated if have time. helping make community forums great place.
click here participate survey.



Visual Studio Languages  ,  .NET Framework  >  Visual C#



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

job syspolicy_purge_history job fail in sqlserver 2008

Trying to register with public marketplace error with 'Get-AzureStackStampInformation'