Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a registry key value

Tags:

c#

.net

registry

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

like image 531
Jla Avatar asked Dec 03 '22 13:12

Jla


2 Answers

The version number is the default value.

To get this you need:

string s = reg.GetValue(null).ToString();
like image 195
ChrisF Avatar answered Dec 06 '22 03:12

ChrisF


RegistryKey key = Registry.ClassesRoot;  
RegistryKey subKey = key.OpenSubKey(@"Excel.Application\CurVer");   

return subKey.GetValue(""); 
like image 44
Jacob Seleznev Avatar answered Dec 06 '22 03:12

Jacob Seleznev