I\'m reading the value of a registry key:
Microsoft.Win32.RegistryKey key;
key = *someLongPathHere*;
and displaying the value to a label:
It's easy enough to test whether or not there is a systematic problem with string values containing underscores. You can simply create such a value in the registry editor and then read it into your C# program with GetValue()
. When you do so you'll discover that the C# registry code doesn't lose underscores. So, there must be some other explanation for your problem.
My best guess is that your label component does not display the underscore. I'm not very familiar with the C# UI frameworks but that seems plausible. Try looking at the value of a
under the debugger rather than in a label caption on your UI.
The other thing that comes to mind is that you have registry redirection because you have an x86 process running on x64, and your key is under a redirected key, HKLM\Software, for example. Perhaps if you look under the Wow6432Node you will see the underscore discrepancy.
As for managing the life of the key, the key is backed by an unmanged resource. Namely a Windows HKEY
. The RegistryKey
class implements IDisposable
and so you should wrap your keys in a using
statement.