What's wrong with Registry.GetValue?

后端 未结 5 1316
轻奢々
轻奢々 2021-01-12 07:25

I trying to get a registry value:

var value = Registry.GetValue(@\"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography\", \"MachineGuid\", 0);
5条回答
  •  渐次进展
    2021-01-12 07:58

    If you're not an administrator, you only have read permission on HKLM. You need to open the key read-only instead. Not sure how to do that with .NET's Registry class; with the API directly, you use RegOpenKeyEx() with the KEY_READ flag.

    EDIT: After checking MSDN, I see that OpenSubKey() does open read only, and returns the contents if it succeeds and nothing if it fails. Since you're chaining multiple OpenSubKey calls, it's most likely one of them that's failing that causes the others to fail. Try breaking them out into separate calls, and checking the intermediate values returned.

提交回复
热议问题