Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"The RPC server is unavailable" using WMI query

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.

I've spent the last few hours digging through everything I can find, but nothing works. I've set permissions for WMI (remote & local), DCOM (remote & 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.

I know the username/passwords I'm using are correct since I can access the shard directories of one from the other

Any ideas of what else I could check that might cause this error?

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);
    }

Server Error in '/' Application.

The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)

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.

Exception Details: System.Runtime.InteropServices.COMException: The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)

Source Error:

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

Source File: c:\Web\medelaimages.com\iis\tool\boxinfoagent.aspx Line: 66

Stack Trace:

[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

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1

like image 536
jwynveen Avatar asked Mar 07 '11 20:03

jwynveen


People also ask

Does WMI use RPC?

WMI technology is based on DCOM / Remote Procedure Call (DCOM/RPC) communication. DCOM/RPC allocates the ports used by the server within a dynamic port range—typically between ports 1024 and 65536. To configure these ports using Windows Firewall on your managed computers, enable the Inbound Rules in the WMI group.

What does it mean when RPC server is unavailable?

The RPC server is unavailable error means your Windows computer is having a problem with communication with other devices or machines through the network you use.


1 Answers

The error The RPC server is unavailable. (Exception from HRESULT: 0x800706BA) can occur if

  • inbound RPC / WMI connections are blocked on the target machine due to Firewall restrictions

    or

  • just because you entered incorrect hostname / IP address of the target machine.

The error occurs before any authentication and/or authorization actions, so dealing with permissions is not required at this step. In fact, if the user account lacks necessary permissions to a particular namespace, you'd get another error and errorcode: access denied. (0x80041003).

The MSDN article covers adding Firewall exceptions for remote WMI access: "Connecting to WMI Remotely".

like image 163
bahrep Avatar answered Sep 18 '22 12:09

bahrep