“RPC 服务器不可用”使用 WMI 查询

发布于 2024-10-20 12:04:15 字数 3503 浏览 1 评论 0原文

我有一个运行 Server 2008 R2 的 Web 服务器工作组,我试图在其中管理一个脚本来检查所有服务器的磁盘空间。几个月前我在设置服务器时就设置了这个,我相信它工作得很好。现在我去检查一下,结果显示错误“RPC 服务器不可用”。该脚本是一个 C# ASP.NET 页面,尽管我在 PowerShell 中尝试过类似的调用,但它给出了相同的错误。该脚本可以正常访问本地计算机的信息,但无法访问远程服务器信息。

在过去的几个小时里,我一直在挖掘我能找到的所有东西,但没有任何效果。我已经为 WMI(远程和本地)、DCOM(远程和本地)以及我正在访问的计算机的整个驱动器设置了权限。我使用了计算机名称、IP 地址、完整计算机名称 (xxx.echomountain.com),并在 ConnectionOptions 对象上尝试了多种模拟和身份验证设置。

我知道我使用的用户名/密码是正确的,因为我可以从另一个访问一个的分片目录。

我还可以检查什么可能导致此错误?

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

“/”应用程序中的服务器错误。

RPC 服务器不可用。 (HRESULT 异常:0x800706BA)

描述:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。

异常详细信息:System.Runtime.InteropServices.COMException:RPC 服务器不可用。 (HRESULT 异常:0x800706BA)

来源错误:

第 64 行: 第65行: //获取结果 第 66 行: ManagementObjectCollection oReturnCollection = oSearcher.Get(); 第 67 行: 第 68 行://循环找到的驱动器并写出信息

源文件:c:\Web\medelaimages.com\iis\tool\boxinfoagent.aspx 行:66

堆栈跟踪:

[COMException (0x800706ba):RPC 服务器不可用。 (HRESULT 异常:0x800706BA)] System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) +0 System.Management.ManagementScope.InitializeGuts(对象o)+674 系统.管理.管理范围.初始化()+347 System.Management.ManagementObjectSearcher.Initialize() +189 System.Management.ManagementObjectSearcher.Get() +54 ASP.tool_boxinfoagent_aspx.Page_Load(对象发送者,EventArgs e)位于 c:\Web\medelaimages.com\iis\tool\boxinfoagent.aspx:66 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp,对象o,对象t,EventArgs e)+25 System.Web.UI.Control.LoadRecursive() +71 System.Web.UI.Page.ProcessRequestMain(布尔 includeStagesBeforeAsyncPoint,布尔 includeStagesAfterAsyncPoint)+3048

版本信息:Microsoft .NET Framework 版本:4.0.30319; ASP.NET版本:4.0.30319.1

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

木格 2024-10-27 12:04:15

错误RPC 服务器不可用。 (HRESULT 异常:0x800706BA)如果

  • 入站 RPC / WMI 连接由于防火墙限制而在目标计算机上被阻止

    , 则可能会发生

  • 仅仅因为您输入了错误的目标计算机主机名/IP 地址,入站 RPC/WMI 连接在目标计算机上被阻止。

该错误发生在任何身份验证和/或授权操作之前,因此此步骤不需要处理权限。事实上,如果用户帐户缺乏对特定命名空间的必要权限,您会收到另一个错误和错误代码:访问被拒绝。 (0x80041003)

MSDN 文章介绍了为远程 WMI 访问添加防火墙例外:“远程连接到 WMI”。

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".

岁吢 2024-10-27 12:04:15

该错误消息告诉您 RPC 被阻止,这是 Windows 7 和 2008 上的默认策略设置。可以通过策略打开它,或者使用 WMI 连接和管理主机。在内部可信网络上,通常会启用 RPC。美国政府计算机安全政策委员会(例如创建 FDCC 和 USGCB 的委员会)没有推荐 RPC 设置,因此启用它是可以的。通过 WMI 管理实时系统非常很困难,因为您无法查看远程主机的注册表、计划任务、文件夹和文件。但是,您可以通过 WMI 轻松管理服务。

The error message is telling you that RPC is blocked, which is the default policy setting on Windows 7 and 2008. Either open it via policy, or use WMI to connect and manage the hosts. On an internal, trusted network, RPC is usually enabled. US government computer security policy boards, like those that created FDCC and USGCB, have no recommended setting for RPC, so it is ok to enable it. Managing live systems via WMI is very difficult since you cannot view remote hosts' registry, scheduled tasks, folders and files. You can, however, easily manage services via WMI.

白馒头 2024-10-27 12:04:15

只需转到 IIS 管理器即可。在应用程序池中启动您的网站服务。
这对我有用

Just Go to IIS manager. Start your website Service in Application pool.
It works for me

_失温 2024-10-27 12:04:15

此外,您需要在远程计算机上的 Windows 防火墙中启用 Windows Management Instrumentation (WMI) 规则。

1] 打开 Windows 防火墙。
2] 单击“允许应用程序或功能通过 Windows 防火墙”。
3]启用Windows管理规范(WMI)的权限。

Also, You need to enable Windows Management Instrumentation (WMI) rule in windows firewall on remote machine.

1] Open Windows Firewall.
2] Click on Allow app or feature through windows firewall.
3] Enable Privilege for Windows Management Instrumentation(WMI).

寄风 2024-10-27 12:04:15

我遇到了同样的问题。早些时候,我在使用服务器 IP 时遇到此错误,但在使用服务器 FQDN 名称后能够连接。故障排除后,我发现我的 DNS PTR 记录不正确。修复后我也能够使用 IP 地址连接 WMI。我使用了wbemtest WMI测试工具。

I faced same issue. Earlier I was getting this error while using server IP but was able to connect after I used server FQDN name. After troubleshooting I found my DNS PTR record was not correct. After fixing that I was able to connect WMI with IP address also. I used wbemtest WMI test tool.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文