Hello I've got a bit of a problem. I'm trying to use WMI to list information about disks. When I run the code from the WMI code creator everything returns fine and I get the information I'm looking for. When I run the code from the application I'm writing I get an invalid class error that gets thrown from the foreach loop.
The code I wrote and WMI generated is essentially the same, only the output is different. What could I possibly be doing wrong. Here is the code I wrote.
public List<diskData> getDiskInfo()
{
List<diskData> dData = new List<diskData>();
diskData mydisk = null;
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM W32_LogicalDisk");
foreach (ManagementObject item in searcher.Get())
{
mydisk.name = Convert.ToString(item["Name"]);
}
return dData;
}
catch (Exception ex)
{
Console.WriteLine("This is the Message: " + ex.Message);
return dData;
}
}
Thanks for any help you guys can provide.
Paul