title: Restart App Pool from ASP.NET via WMI Problems
body: <p>I've been trying to create a C# ASP.NET page which sits on a Windows Server 2003 IIS 6 server and when called (remotely), restarts/recycles a specific application pool on the server.</p>
  
  <p>I've not been having much luck, does anyone know where I'm going wrong? I've tried many combinations and tried running direct from server but to no-avail.</p>
  
  <p>When I don't pass the credentials over I get the error...</p>
  
  <blockquote>
    <p>Access is denied</p>
  </blockquote>
  
  <p>...and when I do pass them I get the error...</p>
  
  <blockquote>
    <p>User credentials cannot be used for local connections</p>
  </blockquote>
  
  <p>I've also tried elevating permissions with the anon account just to test but again it wouldn't work.  Is this possible what I'm trying to achieve?</p>
  
  <pre class="lang-cs prettyprint-override"><code>try
  {
      ManagementScope scope = new ManagementScope("root\\MicrosoftIISv2");
      scope.Path.Server = "servername";
      scope.Path.Path = "\\\\servername\\root\\MicrosoftIISv2";
      scope.Path.NamespacePath = "root\\MicrosoftIISv2";
      scope.Options.Username = "domain\\user";
      scope.Options.Password = "password";
      scope.Options.Authentication = AuthenticationLevel.Default;
      scope.Options.Impersonation = ImpersonationLevel.Impersonate;
      scope.Options.EnablePrivileges = true;
      scope.Connect();
  
      ManagementObject appPool = new ManagementObject(scope, new ManagementPath("IIsApplicationPool.Name='W3SVC/AppPools/AppPoolName'"), null);
      appPool.InvokeMethod("Recycle", null, null);
  }
  catch (System.Exception ex)
  {
  }
  </code></pre>