WMI的问题

问题描述 投票:0回答:1

我正在尝试构建一个可以监视网络上另一台计算机上的应用程序的应用程序,以确保它正在运行。我正在尝试使用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/)有关如何修复代码或其他方式来远程获取服务器上运行的任何建议吗?

c# wmi wmi-query comexception
1个回答
0
投票

有一个错字,它必须是root\cimv2

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

© www.soinside.com 2019 - 2024. All rights reserved.