注册表读取键值问题

ankey888 2017-10-26 04:12:30
string ACCPath = TryGetSoftwarePath(@"SOFTWARE\Microsoft\Office\14.0\Access\InstallRoot", @"Path");


private static string TryGetSoftwarePath(string regPath, string keyName)
{


RegistryKey regKey = null;
RegistryKey regSubKey = null;
try
{
//Read the key
regKey = Registry.LocalMachine;
regSubKey = regKey.OpenSubKey(regPath, RegistryKeyPermissionCheck.ReadSubTree, RegistryRights.ReadKey);

//Read the path
if (regSubKey != null)
{
var objResult = regSubKey.GetValue(keyName);
var regValueKind = regSubKey.GetValueKind(keyName);
if (regValueKind == RegistryValueKind.String)
{
return objResult.ToString();
}
}
}
catch (System.Security.SecurityException ex)
{
throw new System.Security.SecurityException("You have no right to read the registry!", ex);
}
catch (Exception ex)
{
throw new Exception("Reading registry error!", ex);
}
finally
{

if (regKey != null)
{
regKey.Close();
}

if (regSubKey != null)
{
regSubKey.Close();
}
}

return "";
}

为什么上面的键值不存在,还能正常读取呢,哪位能给我解惑下。
...全文
93 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧