title: How to read a large value of type REG_DWORD from the registry?
body: <p>I have the following method:</p>
  <pre><code>public static object GetRegValue(RegistryHive hive, string subKey, string key)
  {
      try
      {
          var view32 = RegistryKey.OpenBaseKey(hive,
                                  RegistryView.Default);
          using (var regKey = view32.OpenSubKey(subKey, false))
          {
              return regKey.GetValue(key, 0);
          }
      }
      catch (Exception)
      {
          Logger.Log($&quot;Get {subKey} + {key} from Registry failed&quot;);
          return 0;
      }
  }
  </code></pre>
  <p>And I use it whenever I need to access a certain registry path.
  However, I found a bug in the following code segment while accessing 0xa8200410 (2820670480)</p>
  <pre><code>Convert.ToUInt64(GetRegValue(RegistryHive.CurrentUser, RegistryPath, RegistryKeyName));
  </code></pre>
  <p>I see that from <code>GetValue()</code> I get <code>Int32</code> value. It gives me some large negative value. So I searched for ways to convert that into <code>ulong</code>.</p>
  <pre><code>var value = 0ul;
  unchecked
  {
      value = (ulong)(int)Misc.GetRegValue(RegistryHive.CurrentUser, RegistryPath, RegistryKeyName);
  }
  </code></pre>
  <p>Still, it gave me the wrong value.</p>
  <p>Can anyone give me an idea on approaching for getting a large DWORD value from the registry in C#?</p>