Hi ,
I am facing an issue with a virtual machine in Hyper-V. The setup is as mentioned below:
- I have a virtual machine (named HV4), it contains Windows 2012 Server. Hyper-V Manager is enabled on this machine.
- There are more than one virtual machines under Hyper-V Manager (HV4 nested) . All machines contains Windows 2012 Server.
- All the machine are connected with External switch and assigned the IP 192.168.x.x. series.
The description of the issue is as below:
Now I want to get list of names of all network adapters of each Virtual Machine like; NetConnectionID (Local Area Connection1, Local Area Connection 2 etc.. ) using C#,WMI (Windows Management Instrumentation) withusing System.Management;
I am using CIM_NetworkAdapter Class (http://msdn.microsoft.com/en-us/library/aa387931%28v=vs.85%29.aspx).
- When the name of the virtual machine in Hyper-V Manager and Computer name of that machine is same then its working fine.
- If I change the Computer name of virtual machine then I get an error Message : “The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)”.
But it works fine in theabove case (i.e. case 1).
The used code is given below:
private void GetNetAdapterInfo()
{
string strVirtualMachineName = string.Empty;
StringBuilder strEthernet = new StringBuilder();
try
{
//create a management scope object
ManagementScope scope = new ManagementScope("\\\\VM2008R2\\ROOT\\cimv2");
//create object query
ObjectQuery query = new ObjectQuery("SELECT * FROM CIM_NetworkAdapter");
//create object searcher
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
//get collection of WMI objects
ManagementObjectCollection queryCollection = searcher.Get();
//enumerate the collection.
foreach (ManagementObject m in queryCollection)
{
// access properties of the WMI object
foreach (PropertyData propNet in m.Properties)
{
strEthernet.Append(propNet.Name + " :\t" + propNet.Value);
strEthernet.Append("\n");
}
}
}
catch (Exception expGetNetAdapterInfo)
{
MessageBox.Show(expGetNetAdapterInfo.GetBaseException().ToString());
}
MessageBox.Show(strEthernet.ToString());
}
Please help me in this regard.
Thanks & Regards
Alok kumar sharma