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 = "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());
}
}
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: https://www.drivereasy.com/knowledge/rpc-server-is-unavailable-error-on-windows-10-fixed/) Any suggestions as to how to fix the code or another way to get what's running on the server remotely?
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.
User contributions licensed under CC BY-SA 3.0