John500
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(subKey Name))
{
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
using (RegistryKey tempKey = test9999.OpenSubKey(subKey
{
foreach (string valueName in tempKey.GetValueNames())
{
Console.WriteLine("{0,-8}:
tempKey.GetValue(valueName
}
If the expression - tempKey.GetValue(valueName
string SubValue = string.Empty;
...
...
SubValue = tempKey.GetValue(valueName
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
See the picture below,
Thanks
reg-routine.jpg
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes, absolutely
ASKER
The picture above shows the runtime value of 'valueName' which is 'MyStringValue' ... this is gotten from the registry.
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.
Is it throwing an error or anything, or is SubValue just staying blank?