我现在有此代码。
string uninstallKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(uninstallKey))
{
foreach (string skName in rk.GetSubKeyNames())
{
using (RegistryKey sk = rk.OpenSubKey(skName))
{
try
{
var displayName = sk.GetValue("DisplayName") as string;
if (displayName.Equals("TimeKeeper"))
{
keyName = skName;
}
}
catch (Exception e) { }
}
}
}
但是我一直在获取System.NullReferenceException。但是,如果我尝试从当前用户注册表中获取值,则不会出现任何错误。有人知道如何解决此问题吗?