嗨,这是我的代码:
RegistryKey baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine,
RegistryView.Registry64).OpenSubKey("SOFTWARE");
String[] str = baseKey.GetSubKeyNames();
for (int i = 0; i < str.Length; i++)
Console.WriteLine(str[i]); //Testing purpose
RegistryKey key =
baseKey.OpenSubKey("Werewolf");
由于for循环打印了所有子键,子键正确,包括“Werewolf”键,但是OpenSubKey("Werewolf")
返回null,我得到了这个异常:
System.NullReferenceException: 'Object reference not set to an instance of an object.'
使用VS2017编译的代码。同时出现在x86和x64机器上,同样的错误。