title: C# Safely Navigate to Registry Path
body: <p>Basically I need to create a path to:  </p>
  
  <blockquote>
    <p>HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\myDomain\Subdomain</p>
  </blockquote>
  
  <p>And create a DWORD named * (an asterisk) with the value of 2
  I get an error during run time in the console and it doesn't do anything.</p>
  
  <p>I assume this is because myDomain\Subdomain doesn't exist.  Here is my code:</p>
  
  <pre><code>RegistryKey myKey = Registry.CurrentUser.OpenSubKey("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Domains\\google.com\\sites", true);
  myKey.SetValue("*", "2", RegistryValueKind.DWord);
  myKey.Close();
  </code></pre>