【问题标题】:Issues with WMIWMI 的问题
【发布时间】:2018-03-02 21:11:36
【问题描述】:

我正在尝试构建一个应用程序,该应用程序可以监视网络上另一台计算机上的应用程序,以确保它正在运行。我正在尝试使用 WMI 来做到这一点。我可以使用 wmimgmt.msc 访问服务器,因此这似乎不是未启用所需服务的问题。以下是我的代码:

ConnectionOptions op = new ConnectionOptions();
op.Username = "domain.com\\Administrator";
op.Password = "Password";
ManagementScope scope = new ManagementScope(@"\\SERVERNAME.Domain\root\cim2", op);
scope.Connect();
ManagementPath path = new ManagementPath("Win32_Service");
ManagementClass services = new ManagementClass(scope, path, null);

foreach (ManagementObject service in services.GetInstances())
{
    lv1.Items.Clear();
    if (service.GetPropertyValue("State").ToString().ToLower().Equals("running"))
    { // Do something }
        lv1.Items.Add(service.ToString());
    }
}

当它运行时,我得到一个 InteropServices.COMException:The RPC server is unavailable. (Exception from HRESULT: 0x800706BA) 我在网上看到的所有修复都没有帮助。 (例如:https://www.drivereasy.com/knowledge/rpc-server-is-unavailable-error-on-windows-10-fixed/)关于如何修复代码或以其他方式远程获取服务器上运行的内容的任何建议?

【问题讨论】:

  • 我假设您已检查 RPC 和 RPC Endpoint Mapper 服务是否正在运行。还要验证防火墙是否启用了 WMI 规则(另外,请在禁用防火墙后尝试)。使用以下设置进行验证:op.EnablePrivileges = true; op.Authentication = AuthenticationLevel.PacketPrivacy; op.Impersonation = ImpersonationLevel.Identify; op.Password = "Password";op.Username = "Username"; op.Authority = "NTLMDOMAIN:domain.com";
  • 两个 RCP 服务都在两台机器上运行。我曾尝试使用上述设置,但.Authority 设置不断给我一个“无效参数”错误。我尝试了一些域名变体,但均未成功。
  • 如果不是拼写错误,如答案所示(另外,用户名是“Administrator”,\\ComputerName\ 只是名称,可以是机器的 IP 地址),请尝试,如ImpersonationImpersonationLevel.Impersonate 或默认的ImpersonationLevel.Unchanged。仔细检查你写的内容。
  • 0x800706BA 错误与防火墙有关(请参阅:WMI Troubleshooting and Tips)。防火墙规则应该是(我现在无法验证)netsh advfirewall firewall set rule group="Windows Remote Management" new enable=yes。 Authority 属性取决于网络身份验证处理程序。您可以将其留空并使用domain\Username 作为用户名。

标签: c# wmi wmi-query comexception


【解决方案1】:

有一个错字,应该是root\cimv2

对于以后的编码,请确保您能够使用wbemtest 获取信息,这将为您节省大量时间和精力。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-02
    • 2011-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多