I need to be able to retrieve (programmatically via C#) some of the information available through Windows Device Manager. Specifically I am referring to information on the Details tab of a Device Properties dialog box. In my case I need to retrieve the "Location Information" property for the network adapters on the PC. Ideally, I would prefer to do this using an API call via WMI or similar but haven't been able to find or figure out how do to that. Anyway, if anyone has any information on how to do this using either DevCon or some series of API calls I would greatly appreciate any help. I found a sample of code in another post here (which I have copied below) but this did not give me the information I am looking for.
private static void test()
{
ManagementPath path = new ManagementPath();
ManagementClass devs = null;
path.Server = ".";
path.NamespacePath = @"root\CIMV2";
path.RelativePath = @"Win32_PnPentity";
System.IO.File.Delete(fileName);
using (devs = new ManagementClass(new ManagementScope(path), path, new ObjectGetOptions(null, new TimeSpan(0, 0, 0, 2), true)))
{
ManagementObjectCollection moc = devs.GetInstances();
foreach (ManagementObject mo in moc)
{
try
{
PropertyDataCollection devsProperties = mo.Properties;
foreach (PropertyData devProperty in devsProperties)
{
if (devProperty.Type == CimType.DateTime)
{
if (devProperty.Value != null)
{
Console.WriteLine("Date {0}", ToDateTime(devProperty.Value.ToString()));
System.IO.File.AppendAllText(fileName, "Date " + ToDateTime(devProperty.Value.ToString()) + Environment.NewLine);
}
}
else
{
Console.WriteLine("Property = {0}\t Value = {1}", devProperty.Name, devProperty.Value);
System.IO.File.AppendAllText(fileName, "Property = " + devProperty.Name + "\t Value = " + devProperty.Value + Environment.NewLine);
}
}
if (String.IsNullOrEmpty(mo["DeviceID"].ToString()))
{
System.IO.File.AppendAllText(fileName, "Device ID was NULL" + Environment.NewLine);
Console.WriteLine("****** Device ID was NULL ******");
continue;
}
int count = 0;
RelatedObjectQuery relatedQuery;
try
{
relatedQuery = new RelatedObjectQuery("associators of {Win32_PnPEntity.DeviceID='" + mo["DeviceID"] + "'}");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(new ManagementScope(path), relatedQuery);
foreach (ManagementObject mob in searcher.Get())
{
System.IO.File.AppendAllText(fileName, "--------------------------->>>>>>" + Environment.NewLine);
Console.WriteLine("--------------------------->>>>>>");
System.IO.File.AppendAllText(fileName, mob["Description"].ToString() + Environment.NewLine);
Console.WriteLine(mob["Description"]);
++count;
}
}
catch (Exception fEx)
{
string temp = fEx.Message;
continue;
}
System.IO.File.AppendAllText(fileName, "----------------------" + Environment.NewLine);
Console.WriteLine("----------------------");
}
catch (Exception fEx)
{
string temp = fEx.Message;
}
}