[英]How to get the default value of key from the registry
I am trying get the (Default)
key value from the HKEY_CLASSES_ROOT
and the code snippet I tried is as below, 我正在尝试从HKEY_CLASSES_ROOT
获取(Default)
键值,我尝试的代码片段如下所示,
using (var key = Registry.ClassesRoot.OpenSubKey(@"Excel.Application\\CurVer"))
{
var defvalue = key?.GetValue("(Default)");
if (defvalue != null)
{
}
}
Always the defvalue
is coming as null. 始终, defvalue
将defvalue
null。 I am not able trace out what mistake I am doing. 我无法弄清楚我在做什么错。
Could anyone please help me to resolve this. 有谁可以帮我解决这个问题。
Instead of using "(Default)" you need to use an emtpy string "". 而不是使用“(默认)”,你需要使用一个emtpy字符串“”。
using (var key = Registry.ClassesRoot.OpenSubKey(@"Excel.Application\\CurVer"))
{
var defvalue = key?.GetValue("");
if (defvalue != null)
{
}
}
您还可以尝试使用“String.Empty”来获取注册表的“(默认)”值,而不是在代码中访问“(默认)”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.