title: C# WPF - Registry Access not Allowed, even with Administrator Privileges?
body: <p>I've recently been working on a very nice Registry Editor.</p>
  
  <p>However, certain Registry keys, pointed out below in Regedit, will not show up in my program, as they raise an error of insufficient privileges when opened, and so are caught by error handling and skipped:</p>
  
  <p>Regedit:</p>
  
  <p><a href="https://i.stack.imgur.com/OOm2U.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OOm2U.png" alt="Registry 1"></a></p>
  
  <p>My program:</p>
  
  <p><a href="https://i.stack.imgur.com/1iWl7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1iWl7.png" alt="Registry 2"></a></p>
  
  <p>As you can see, the SECURITY key is missing, and the SAM key is not expandable, even though I am running the program with administrator privileges.</p>
  
  <p>This can obviously be fixed by making fake keys and putting them there, and just displaying an empty default value for them, however that isn't a concrete solution, just a way to make it seem to the user as if the issue is solved.</p>
  
  <p>I was wondering if there is a way to fix the issue in a concrete way, or in other words, to receive registry access to those keys?</p>
  
  <p>All they display is an empty default value any way, including the expandable SAM key - it just has a subkey named 'SAM' with an empty default value as well.</p>
  
  <p>However, to the user, it's much better if the program displays exactly as in Regedit, as it means that it's a fully functional piece of software.</p>
  
  <p>Thanks for the help.</p>
  
  <p>Edit (code included):</p>
  
  <pre><code>public static void TreeViewItemExpanded(TreeViewItem sender)
          {
              if (sender.Items[0] is string)
              {
                  sender.Items.Clear();
  
                  RegistryKey expandedKey = (RegistryKey)sender.Tag;
  
                  foreach (string key in expandedKey.GetSubKeyNames().OrderBy(x =&gt; x)) try { sender.Items.Add(CreateTreeViewItem(expandedKey.OpenSubKey(key))); } catch { }
              }
          }
  
          private static TreeViewItem CreateTreeViewItem(RegistryKey key)
          {
              TreeViewItem treeViewItem = new TreeViewItem() { Header = new RegistryEditor_RegistryStructure_TreeView() { Name = Path.GetFileName(key.ToString()) }, Tag = key };
  
              try { if (key.SubKeyCount &gt; 0) treeViewItem.Items.Add("Loading..."); } catch { }
  
              return treeViewItem;
          }
  </code></pre>