Reputation: 89
Problem
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\SystemProtectedUserData\S-1-5-21-436374069-1965331169-839522115-50811\AnyoneRead\LockScreen.
Using Code:
Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\SystemProtectedUserData\S-1-5-21-436374069-1965331169-839522115-50811\AnyoneRead\LockScreen", "", null);
Diagnostics of problem
I get a System.NullReferenceException when executing code like the key does not exits, but I know it exist because I can view it in regedit.
I have tried to take ownership of the key.
I have tried viewing subkeys of parent key (CurrentVersion). The parent scan never even showed the key SystemProtectedUserData key same with the key right under TabletPC.
I am guessing this is some permission problem but I dont know how to fix it.
Any help is appreciated.
Upvotes: 0
Views: 531
Reputation: 23308
Your Registry.GetValue
method returns null
, because it can't find a specified key or value and the default value (the third argument) is set to null
. According to documentation, this method can't throw a NullReferenceException
, it seems the consuming code causes it.
So, you can try to specify the value name (at my end I see only OSVersion
value) or different default value.
If the issue still exist, the problem can be in redirection to WOW6432Node
registry node in x64 edition of Windows. You can avoid it by the following code, using OpenBaseKey
method and specifying a RegistryView
value
var baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
var key = baseKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\SystemProtectedUserData\S-1-5-21-...\AnyoneRead\LockScreen");
var value = key.GetValue("OSVersion"); //for example
Upvotes: 3
Reputation: 529
You didn't define the valueName
thus it returns the default value, which you set to null.
Check the documentation. (More specifically, you defined it to string.Empty
which is not a valid name. Maybe LockScreen is the name of the value/registry-variable? - I don't speak android)
Upvotes: 0