Are you running a 32-bit process? On my system the key exists in the 64-bit view of the registry.
Why is the Registry Key showing null in C# even if it is present in Registry Editor?

Here is my C# code:
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Multimedia\SystemProfile", true))
{
key.CreateSubKey("NetworkThrottlingIndex");
key.SetValue("NetworkThrottlingIndex", "0000000a", RegistryValueKind.DWord);
key.CreateSubKey("SystemResponsiveness");
key.SetValue("SystemResponsiveness", "00000000", RegistryValueKind.DWord);
key.CreateSubKey("NoLazyMode");
key.SetValue("NoLazyMode", "1");
}
So what is happening here is that I am getting an error
System.NullReferenceException
on the line
key.CreateSubKey("NetworkThrottlingIndex");
because the key is null.
I checked several times but this key is present in my registry editor.
Any idea about what is wrong here?
3 answers
Sort by: Most helpful
-
-
vcrobe 1 Reputation point
2022-10-27T20:03:46.963+00:00 I think that key is null for one of two reasons:
- The key was not found so OpenSubKey() will return null
- You don't have permissions to open that key in write mode
-
Castorix31 71,626 Reputation points
2022-10-27T20:19:30.083+00:00 Try RegistryView.Registry64 like the test I had posted in this thread