title: How to troubleshoot UnauthorizedAccessException when calling ManagementScope.Connect()
body: <p>I am looking for ideas to gather more information from the system about why a remote WMI call is failing.</p>
  
  <p>The detailed steps in <a href="https://serverfault.com/questions/28520/which-permissions-rights-does-a-user-need-to-have-wmi-access-on-remote-machines">Which permissions/rights does a user need to have WMI access on remote machines?</a> were helpful, but either I've accidentally missed something or there is something more that needs to be configured for my environment.</p>
  
  <p>I am seeing the following exception when I run the .NET 4.0 C# code (snippet below):</p>
  
  <blockquote>
    <p>System.UnauthorizedAccessException occurred   Message=Access is
    denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))<br>
    Source=System.Management   StackTrace:
           at System.Management.ThreadDispatch.Start()
           at System.Management.ManagementScope.Initialize()
           at System.Management.ManagementScope.Connect()
           at MyNamespace.MyClass.GetWmiInfo() in...</p>
  </blockquote>
  
  <p>This is the code where the error occurs. The exception is thrown on the call to <a href="http://msdn.microsoft.com/en-us/library/system.management.managementscope.connect.aspx" rel="nofollow noreferrer">Connect()</a>.</p>
  
  <pre><code>var scope = new ManagementScope("\\\\HOSTNAME\\root\\cimv2")
  {
      Options =
      {
          Impersonation = ImpersonationLevel.Impersonate,
          Password = "password",
          Username = "domain\\username"
      }
  };
  
  scope.Connect();
  </code></pre>
  
  <p>The code is being run on a Windows 7 computer, and the target of the WMI connection is a Windows XP computer. <em>Note: I see a similar problem if I reverse the two roles.</em></p>
  
  <p>I don't see any errors logged in the target computer's security log.</p>
  
  <p>If I add the user whose credentials are being used to the Administrators group on the target computer, the call to <code>Connect()</code> succeeds, so the problem does seem to really be due to a privilege or access which is not yet granted.</p>
  
  <p>Normally when I encounter access-denied errors I would be able to find an entry in a log that gives more detail, or would be able to run <strong>regmon</strong> or <strong>filemon</strong> to capture some useful information. But with this WMI / DCOM error, I don't know where else to look for more information.</p>
  
  <p>Any suggestions much appreciated!</p>
  
  <p><strong>Update:</strong> I tested using <a href="http://technet.microsoft.com/en-us/library/cc180684.aspx" rel="nofollow noreferrer">WBEMTest.exe</a> and found that access is also denied, unless I run as an administrator. I am trying to continue working with this tool to further isolate the problem.</p>