0

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?

B Minster
  • 331
  • 3
  • 16
  • I assume you have checked that the RPC and RPC Endpoint Mapper services are running. Also verify whether the Firewall has a WMI rule enabled (also, try after having disabled the Firewall). Verify it with these settings: `op.EnablePrivileges = true; op.Authentication = AuthenticationLevel.PacketPrivacy; op.Impersonation = ImpersonationLevel.Identify; op.Password = "Password";op.Username = "Username"; op.Authority = "NTLMDOMAIN:domain.com";` – Jimi Mar 03 '18 at 03:32
  • The two RCP services are running on both machines. I have tried using the above settings but the `.Authority` setting keeps giving me an 'Invalid Parameter' error. I have tried a few variations of the domain name without success. – B Minster Mar 05 '18 at 18:26
  • If it's not a typo of sort, as the answer suggests (also, username is "Administrator" and \\ComputerName\ is just the name and can be the IP address of the machine), try, as `Impersonation`, `ImpersonationLevel.Impersonate` or the default `ImpersonationLevel.Unchanged`. Double check what you have written. – Jimi Mar 06 '18 at 06:12
  • The 0x800706BA error is Firewall related (see: [WMI Troubleshooting and Tips](https://technet.microsoft.com/en-us/library/ee692772.aspx)). The Firewall rule should be (I can't verify right now) `netsh advfirewall firewall set rule group="Windows Remote Management" new enable=yes`. The Authority property depends on the network authentication handler. You can leave it blank and use `domain\Username` as user name. – Jimi Mar 06 '18 at 06:52

1 Answers1

0

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.

Amit Shakya
  • 1,396
  • 12
  • 27