Question

Summary: is it possible to specify a port to use when querying WMI using System.Management;

I have a python script under Linux that queries, using WBEM, classes on a number of ESXi servers to check for warnings or errors on various subsystems. Previously, separately, I have written a WPF application that queries a number of WinTel boxes for their disk consumption etc. using WMI.

I am wanting to write a new WPF application that will perform the same function as the script and I thought I would be able to do this with WMI. Below is my testing code with the error handling removed for brevity, SetOptions is a private function that provides the username and password:

 foreach (string hostname in Properties.Settings.Default.Hosts)
     foreach (string WMIclass in Properties.Settings.Default.Classes)
     {
     ObjectQuery Query = new ObjectQuery("SELECT * FROM " + WMIclass);
     ManagementObjectSearcher mos = GetMos(Query, hostname);
     foreach (ManagementObject mo in mos.Get())
         foreach (PropertyData pdc in mo.Properties)
             Debug.WriteLine(pdc.Name + " \t\t: " + pdc.Value);
     }

private ManagementObjectSearcher GetMos(ObjectQuery Query, string Hostname)
{
     ConnectionOptions Options = SetOptions();
     ManagementScope Scope = new ManagementScope("\\\\" + Hostname + "\\root\\cimv2", Options);
     return new ManagementObjectSearcher(Scope, Query);
}

The trouble is I get a RPC unavailable on the remote server. I think that is because I am first trying to establish a RPC call on 135 which is not hosted by an ESX server. My question is how can one specify the port 5989 or is there something straightforward I can use in .net to perform what I need to do. Naively I'm thinking the class structure looks the same between WMI/WBEM surely it can be done :-/

Was it helpful?

Solution 2

As said WMI Classes in .net don't support WBEM. In the end I ended up writing some code around the VMware.Vim.dll which has some good documentation on what I needed to do.

OTHER TIPS

System.Management can only be used to connect to other Windows machines running WMI, and doesn't support WBEM. The only C# WBEM client library I seen is http://code.google.com/p/wbemtools/, but it doesn't look very mature.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top