wmi

G

Guest

Hi, I am having problems w/ WMI in C#.

1. I want to get the type of Hardware Abstraction Layer (HAL) of the current
system. I know it's in WMI "Win32_PnPEntity" class with
"DeviceID='ROOT\\ACPI_HAL\\0000'" and attribute "Caption". My code:
....
ManagementObjectSearcher Searcher = new ManagementObjectSearcher("SELECT
Caption from Win32_PnPEntity WHERE DeviceID='ROOT\\ACPI_HAL\\0000'");
ManagementObjectCollection Coll = Searcher.Get();
foreach(ManagementObject mo in m_WMIColl)
{
HAL = mo[Property].ToString();
break;
}
....

It fails when tries to get a ManagementObject (foreach loop). I ran the
query in WMI CIM Studio (from WMI SDK), it works just fine. Anyone knows why?

2. I am also trying to get the chassis type of the current system. This
info is stored in WMI "Win32_SystemEnclosure" class, attribute
"ChassisTypes". However ChassisTypes is an uint16 array. My code:
....
ManagementObjectSearcher Searcher = new ManagementObjectSearcher("SELECT
ChassisTypes from Win32_SystemEnclosure");
ManagementObjectCollection Coll = Searcher.Get();
foreach(ManagementObject mo in m_WMIColl)
{
// I don't know what goes here
break;
}
....

How do I get this uint16[]?

Please help, thank you.
-P
 
W

Willy Denoyette [MVP]

1.
Use:
@"SELECT Caption from Win32_PnPEntity WHERE DeviceID='ROOT\\ACPI_HAL\\0000'"
or:
SELECT Caption from Win32_PnPEntity WHERE
DeviceID='ROOT\\\\ACPI_HAL\\\\0000'

2.
// I know what goes here ;-)
foreach(ushort v in mo.Properties["ChassisTypes"].Value as ushort[])
{
Console.WriteLine(v);
}

Willy.
 
G

Guest

man... you are da man! thanks! =)

-P


Willy Denoyette said:
1.
Use:
@"SELECT Caption from Win32_PnPEntity WHERE DeviceID='ROOT\\ACPI_HAL\\0000'"
or:
SELECT Caption from Win32_PnPEntity WHERE
DeviceID='ROOT\\\\ACPI_HAL\\\\0000'

2.
// I know what goes here ;-)
foreach(ushort v in mo.Properties["ChassisTypes"].Value as ushort[])
{
Console.WriteLine(v);
}

Willy.

Paul said:
Hi, I am having problems w/ WMI in C#.

1. I want to get the type of Hardware Abstraction Layer (HAL) of the
current
system. I know it's in WMI "Win32_PnPEntity" class with
"DeviceID='ROOT\\ACPI_HAL\\0000'" and attribute "Caption". My code:
...
ManagementObjectSearcher Searcher = new ManagementObjectSearcher("SELECT
Caption from Win32_PnPEntity WHERE DeviceID='ROOT\\ACPI_HAL\\0000'");
ManagementObjectCollection Coll = Searcher.Get();
foreach(ManagementObject mo in m_WMIColl)
{
HAL = mo[Property].ToString();
break;
}
...

It fails when tries to get a ManagementObject (foreach loop). I ran the
query in WMI CIM Studio (from WMI SDK), it works just fine. Anyone knows
why?

2. I am also trying to get the chassis type of the current system. This
info is stored in WMI "Win32_SystemEnclosure" class, attribute
"ChassisTypes". However ChassisTypes is an uint16 array. My code:
...
ManagementObjectSearcher Searcher = new ManagementObjectSearcher("SELECT
ChassisTypes from Win32_SystemEnclosure");
ManagementObjectCollection Coll = Searcher.Get();
foreach(ManagementObject mo in m_WMIColl)
{
// I don't know what goes here
break;
}
...

How do I get this uint16[]?

Please help, thank you.
-P
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top