Discussion:
How do you query a member object within a WMI class?
(too old to reply)
Drew K.
2009-05-26 18:17:01 UTC
Permalink
Here's the situation:

I'm looking at the WMI Object Browser and it looks like
MSiSCSIInitiator_SessionClass has a member MSiSCSIInitiator_DeviceOnSession
object array. As I am still very green to WMI, I'm not sure how to access
that array, and more specifically, the single object that it's going to
contain for me in order to pull the DeviceNumber, LegacyName, and TargetName
properties from it. Is there an example or tutorial that I can look at on
how to do this?

Thanks,
~Drew
Drew K.
2009-05-26 19:13:01 UTC
Permalink
Looks like I answered my own question. I'll post it here for anyone else
that may have a related problem.

Cast the result you pull from the original query result property as a
ManagementBaseObject[] and then step through the array and reference the
desired properties from each element.

So basically:

ManagementObjectSearcher searcher = new
ManagementObjectSearcher("root\\WMI", "SELECT * FROM
MSiSCSIInitiator_SessionClass");

foreach (ManagementObject queryObj in sercher.Get())
{
ManagementBaseObject[] arrDevices =
(ManagementBaseObject[])(queryObj["Devices"]);

foreach(ManagementBaseObject arrValue in arrDevices)
{
Console.WriteLine("DeviceNumber: {0}", arrValue["DeviceNumber"]);
}
}
Post by Drew K.
I'm looking at the WMI Object Browser and it looks like
MSiSCSIInitiator_SessionClass has a member MSiSCSIInitiator_DeviceOnSession
object array. As I am still very green to WMI, I'm not sure how to access
that array, and more specifically, the single object that it's going to
contain for me in order to pull the DeviceNumber, LegacyName, and TargetName
properties from it. Is there an example or tutorial that I can look at on
how to do this?
Thanks,
~Drew
Loading...