Link to home
Start Free TrialLog in
Avatar of John500
John500Flag for United States of America

asked on

How to save a registry key value to string

Using Microsoft's example of scrolling registry subkeys we have the following code:


        using (RegistryKey tempKey = test9999.OpenSubKey(subKeyName))
                {
      foreach (string valueName in tempKey.GetValueNames())
                {
              Console.WriteLine("{0,-8}: {1}", valueName,
              tempKey.GetValue(valueName).ToString());
        }

If the expression - tempKey.GetValue(valueName).ToString() - will write out to the console as a string why won't the following assignment work:

string SubValue = string.Empty;
...
...
SubValue  = tempKey.GetValue(valueName).ToString());

In debug mode, SubValue is assigned:  ""

If I evaluate the contents of 'valueName' by hovering over the variable during debug it shows the true value "My String Value"

Why would this be?

Thanks
   
ASKER CERTIFIED SOLUTION
Avatar of Daniel Junges
Daniel Junges
Flag of Brazil image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Looks like you have an extra parenthesis, but that is probably just a typo.

Is it throwing an error or anything, or is SubValue just staying blank?
Avatar of John500

ASKER

SubValue just stays blank - no error is thrown.  I tried the Convert.ToString(....) approach but that made no difference.

See the picture below,
Thanks
reg-routine.jpg
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of John500

ASKER

Yes, absolutely
Avatar of John500

ASKER

The picture above shows the runtime value of 'valueName' which is 'MyStringValue' ... this is gotten from the registry.
Avatar of John500

ASKER

Instead of getting the value I really need to be getting the name.  That's why 'valueName' shows the name but there was no value.