title: "The RPC server is unavailable" using WMI query
body: <p>I have a workgroup of web servers running Server 2008 R2 in which I'm trying to manage a script that checks the disk space of all of them. I had set this up a few months ago when the servers were being set up and I believe it was working fine. Now I go and check and it's giving an error saying "The RPC server is unavailable". The script is a C# ASP.NET page, though I've tried comparable calls in PowerShell and it gives the same error. The script works fine to access the information for the local machine, but can't access remote server info.</p>
  
  <p>I've spent the last few hours digging through everything I can find, but nothing works. I've set permissions for WMI (remote &amp; local), DCOM (remote &amp; local), and the whole drive of the computer I'm accessing. I've used the computer name, IP address, full computer name (xxx.echomountain.com), and tried numerous impersonation and authentication settings on the ConnectionOptions object.</p>
  
  <p>I know the username/passwords I'm using are correct since I can access the shard directories of one from the other</p>
  
  <p>Any ideas of what else I could check that might cause this error?</p>
  
  <pre><code>ConnectionOptions oConn = new ConnectionOptions();
      oConn.Impersonation = ImpersonationLevel.Impersonate;
      oConn.EnablePrivileges = true;
      oConn.Username = username;
      oConn.Password = password;
      //oConn.Authentication = AuthenticationLevel.PacketPrivacy;
      string strNameSpace = @"\\";
  
      if (srvname != "")
          strNameSpace += srvname + ".echomountain.com";
      else
          strNameSpace += ".";
  
      strNameSpace += @"\root\cimv2";
  
      ManagementScope oMs = new ManagementScope(strNameSpace, oConn);
  
      //get Fixed disk state
      ObjectQuery oQuery = new ObjectQuery("select FreeSpace,Size,Name from Win32_LogicalDisk where DriveType=3");
  
      //Execute the query
      ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oMs, oQuery);
  
      //Get the results
      ManagementObjectCollection oReturnCollection = oSearcher.Get();
  
      //loop through found drives and write out info
      double D_Freespace = 0;
      double D_Totalspace = 0;
      foreach (ManagementObject oReturn in oReturnCollection)
      {
          // Disk name
          //MessageBox.Show("Name : " + oReturn["Name"].ToString());
          // Free Space in bytes
          string strFreespace = oReturn["FreeSpace"].ToString();
          D_Freespace = D_Freespace + System.Convert.ToDouble(strFreespace);
          // Size in bytes
          string strTotalspace = oReturn["Size"].ToString();
          D_Totalspace = D_Totalspace + System.Convert.ToDouble(strTotalspace);
          boxSize = (D_Totalspace / GB).ToString("##.00");
          boxFree = (D_Freespace / GB).ToString("##.00");
          Response.Write(srvname + ":" + boxSize + ":" + boxFree);
      }
  </code></pre>
  
  <blockquote>
    <p>Server Error in '/' Application.</p>
    
    <p>The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)</p>
    
    <p>Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. </p>
    
    <p>Exception Details: System.Runtime.InteropServices.COMException: The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)</p>
    
    <p>Source Error: </p>
    
    <p>Line 64: 
    Line 65:         //Get the results
    Line 66:         ManagementObjectCollection oReturnCollection = oSearcher.Get();
    Line 67: 
    Line 68:         //loop through found drives and write out info</p>
    
    <p>Source File: c:\Web\medelaimages.com\iis\tool\boxinfoagent.aspx    Line: 66 </p>
    
    <p>Stack Trace: </p>
    
    <p>[COMException (0x800706ba): The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)]
       System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) +0
       System.Management.ManagementScope.InitializeGuts(Object o) +674
       System.Management.ManagementScope.Initialize() +347
       System.Management.ManagementObjectSearcher.Initialize() +189
       System.Management.ManagementObjectSearcher.Get() +54
       ASP.tool_boxinfoagent_aspx.Page_Load(Object sender, EventArgs e) in c:\Web\medelaimages.com\iis\tool\boxinfoagent.aspx:66
       System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
       System.Web.UI.Control.LoadRecursive() +71
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3048</p>
    
    <p>Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1</p>
  </blockquote>