开发者

Using System.Management to Query a VMware Server

开发者 https://www.devze.com 2023-03-08 03:53 出处:网络
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 f

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 rem开发者_如何学Pythonote 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 :-/


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消