G
Guest
I have been using the following code in a vbs script:
This is a WMI query and I have omitted the connection strings...
set Chassis = objService.ExecQuery("Select ChassisTypes from
Win32_SystemEnclosure Where tag = 'system enclosure 0'")
for each item in Chassis
rs("ChassisType") = item.chassistypes(0)
next
This query returns a collection of values and I only want the first one.
"item.chassistypes(0)"
I want to convert this to C# however I am having some trouble figuring out
how to work through the object. Here is what I have so far...
ManagementObjectCollection collection = searcher.Get();
foreach (ManagementObject m in collection)
{
_chassisType = m[@"ChassisTypes(0)"].ToString();
}
This generate the error:
System.Management.ManagementException: Not found
at
System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus
errorCode)
at System.Management.PropertyData.RefreshPropertyInfo()
at System.Management.PropertyDataCollection.get_Item(String propertyName)
at System.Management.ManagementBaseObject.GetPropertyValue(String
propertyNam e)
at System.Management.ManagementBaseObject.get_Item(String propertyName)
at FirstInv.Chassis.Get(String name) in C:\... Line 41
If possible could you point me in the right direction?
Thanks!
This is a WMI query and I have omitted the connection strings...
set Chassis = objService.ExecQuery("Select ChassisTypes from
Win32_SystemEnclosure Where tag = 'system enclosure 0'")
for each item in Chassis
rs("ChassisType") = item.chassistypes(0)
next
This query returns a collection of values and I only want the first one.
"item.chassistypes(0)"
I want to convert this to C# however I am having some trouble figuring out
how to work through the object. Here is what I have so far...
ManagementObjectCollection collection = searcher.Get();
foreach (ManagementObject m in collection)
{
_chassisType = m[@"ChassisTypes(0)"].ToString();
}
This generate the error:
System.Management.ManagementException: Not found
at
System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus
errorCode)
at System.Management.PropertyData.RefreshPropertyInfo()
at System.Management.PropertyDataCollection.get_Item(String propertyName)
at System.Management.ManagementBaseObject.GetPropertyValue(String
propertyNam e)
at System.Management.ManagementBaseObject.get_Item(String propertyName)
at FirstInv.Chassis.Get(String name) in C:\... Line 41
If possible could you point me in the right direction?
Thanks!