I'm trying to retrieve the value of a (REG_SZ) registry key and write it to a string. However this code seems to think the key is null or doesn't exist and won't allow me to GetValue()
it. Here's the code I'm using to retrieve the value.
string s64BasePath = "SOFTWARE\\Wow6432Node\\Xactware\\";
private void versionSelectorBox_SelectedIndexChanged(object sender, EventArgs e)
{
showForms();
sVersionSelected = versionServerBox.Text;
if (b64Bit == true)
{
string sRKey = s64BasePath + sVersionSelected + "\\"; //Reads as SOFTWARE\\Wow6432Node\\Xactware\\Xactimate28\\
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(sRKey))
{
if (key != null)
{
//label1.Text = "Test."; //Reaches this point just fine
Object o = key.GetValue("Location");
if (o != null)
{
//label1.Text = "Test."; //Does not reach this point, o = null?
sLocationKey = Convert.ToString(o);
}
}
}
//label1.Text = sLocationKey;
}
Here is what the registry looks like. As you can see the Location key exists in the path provided. However the code isn't dropping into the inner most if statement, acting like the o
object is null.
Thanks in Advance.
I will be honest, without having Xactimate installed, I do not have the same registry entry you do so I used Skype as my key.
I changed one thing, I changed it from \ to using the literal string flag. FYI, I ran in this in LINQPad so ignore the 'dump' commands
var test = @"SOFTWARE\Wow6432Node\Skype\Phone";
var reg = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(test);
reg.Dump("OpenSubKey: ");
var result = reg.GetValue("SkypeFolder");
result.Dump("GetValue: ");
Here are the results from the two dumps