tags:

views:

209

answers:

2

I'm trying to retrieve the version of excel from the registry but I have problems using the

Registry.GetValue(...) method

The value I am trying to retrieve is in HKEY_CLASS_ROOT\Excel.Application\CurVer But I do not know what name to put as a parameter in the GetValue method.

I tried :

RegistryKey key = Registry.ClassesRoot;
RegistryKey subKey = key.OpenSubKey(@"Excel.Application\CurVer"); 
// Also tried w/o the "\CurVer"
return subKey.GetValue("CurVer");

But I keep getting a NullReferenceException on the GetValue

+3  A: 

The version number is the default value.

To get this you need:

string s = reg.GetValue(null).ToString();
ChrisF
So simple :s thanks. I've even tried "default" or with no parameter but didn't think of null. Need a coffee
DrDro
A: 
RegistryKey key = Registry.ClassesRoot;  
RegistryKey subKey = key.OpenSubKey(@"Excel.Application\CurVer");   

return subKey.GetValue(""); 
Jacob Seleznev