title: "Cannot write to the registry key" error while editing the DisableTaskMgr value
body: <p>I'm having difficulty changing the <code>DisableTaskMgr</code> value in the registry.  Here's what I'm trying so far:</p>
  
  <pre><code>RegistryKey taskMgr = Registry.CurrentUser.OpenSubKey("Software").OpenSubKey("Microsoft").OpenSubKey("Windows").OpenSubKey("CurrentVersion").OpenSubKey("Policies");
  
  string[] subKeys = taskMgr.GetSubKeyNames();
  bool foundSystemKey = false;
  foreach (string s in subKeys)
    if (s == "System")
    {
      foundSystemKey = true;
      break;
    }
  if (!foundSystemKey)
  {
    taskMgr = taskMgr.CreateSubKey("System"); 
  // here is where I'm getting the exception even when I do OpenSubkey("Policies" , true)
  }
  
  taskMgr.OpenSubKey("System", true);
  taskMgr.SetValue("DisableTaskMgr", 1); // 0 to enable, 1 to disable.
  </code></pre>
  
  <p>I've also tried the following, am seeing the same error get thrown while executing the last line:</p>
  
  <pre><code>RegistrySecurity myRegSecurity = taskMgr.GetAccessControl();
  string User = System.Environment.UserName;
  myRegSecurity.ResetAccessRule(new RegistryAccessRule(User, RegistryRights.FullControl , AccessControlType.Allow));
  taskMgr.SetAccessControl(myRegSecurity); // right here ..
  </code></pre>
  
  <p>Do you have any explanation as to what's going wrong?  Thanks in advance :)</p>