Issues with WMI


I'm trying to build an application that can monitor an application on another computer on the network to ensure that it is running. I'm trying to use WMI to do that. I am able to access the server with wmimgmt.msc so it doesn't seem to be an issue of services not being enabled that are needed. Below is my code:

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

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

When this runs I get an InteropServices.COMException: The RPC server is unavailable. (Exception from HRESULT: 0x800706BA) None of the fixes that I have seen online have helped. (ex: Any suggestions as to how to fix the code or another way to get what's running on the server remotely?

asked on Stack Overflow Mar 2, 2018 by B Minster

1 Answer


There is a typo,it has to be root\cimv2.

For future coding, make sure you are able to fetch the information using wbemtest, it will save you lots of time and effort.

answered on Stack Overflow Mar 6, 2018 by Amit Shakya

User contributions licensed under CC BY-SA 3.0