0
private void button1_Click(object sender, EventArgs e)
{
      int i = (Int32)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Beerbaum", "TCP_Listening_Delay", null);
      MessageBox.Show(i.ToString());
}

In the Registry there is a QWORD-Value(64-Bit) called TCP_Listening_Delay and its value is dec:5000

When I press the button it should open a MessageBox which should display 5000, but it doesn't. All it does is giving me,

"NullReferenceException was unhandled".

Shree
  • 203
  • 3
  • 22
Pat
  • 3
  • 2
  • Possible duplicate of [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Rand Random Sep 21 '18 at 09:55
  • For everybody who has the same Problem but no answer. I used the code from @Saruman and changed the Propertys to `RegistryRights.ReadKey` – Pat Sep 21 '18 at 13:34

1 Answers1

0

Registry.GetValue(String, String, Object) Method

Retrieves the value associated with the specified name, in the specified registry key. If the name is not found in the specified key, returns a default value that you provide, or null if the specified key does not exist.

Returns

null if the subkey specified by keyName does not exist; otherwise, the value associated with valueName, or defaultValue if valueName is not found.

However i think your problem is you are probably trying to read 64/32 bit registry hive from a 32/64 bit application

RegistryView Enumeration : On the 64-bit version of Windows, portions of the registry are stored separately for 32-bit and 64-bit applications. There is a 32-bit view for 32-bit applications and a 64-bit view for 64-bit applications.

You can specify a registry view when you use the OpenBaseKey and OpenRemoteBaseKey(RegistryHive, String, RegistryView) methods, and the FromHandle property on a RegistryKey object.

using (var baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64))
{
   using (var subKey = baseKey.OpenSubKey("blah", RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryRights.FullControl))
   {
      if (subKey != null)
      {
         var value =  subKey.GetValue("Somekey");
      }
   }
}

64 bit Registry Key not updated by 32 bit application

TheGeneral
  • 79,002
  • 9
  • 103
  • 141