简体   繁体   English

获取注册表项值

[英]Get a registry key value

I'm trying to retrieve the version of excel from the registry but I have problems using the 我正在尝试从注册表中检索excel的版本,但我在使用时遇到了问题

Registry.GetValue(...) method Registry.GetValue(...)方法

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. 我试图检索的值是在HKEY_CLASS_ROOT \\ Excel.Application \\ CurVer但我不知道在GetValue方法中作为参数放置什么名称。

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 但是我一直在GetValue上得到一个NullReferenceException

The version number is the default value. 版本号是默认值。

To get this you need: 要得到这个,你需要:

string s = reg.GetValue(null).ToString();
RegistryKey key = Registry.ClassesRoot;  
RegistryKey subKey = key.OpenSubKey(@"Excel.Application\CurVer");   

return subKey.GetValue(""); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM