Discussion:
Get Array Values from WMI Query
(too old to reply)
Bill208
2011-01-05 19:27:33 UTC
Permalink
Hi All,
I'm trying to figure out how to get the array values from a WMI
query. When I have a query with no array values like below I have no
issues and my code works just fine.

select Name, Availability, MaxClockSpeed, CpuStatus from
Win32_Processor

But when I try to use a query to return some array values I get an
"Invalid Query" exception, like from the query below:

select
DomainDeny[],DomainGrant[],GrantByDefault,IPDeny[],IPGrant[],Name from
IIsIPSecuritySetting

So apparently you have to handle the array data types differently. I
just can't seem to figure out how. Any thoughts on how to get this?

Thanks,
Bill

Below is my code for getting this data:

string remoteComputer = "\\\\" + _server + "\\root\\" + _wmiNamespace;
ConnectionOptions oConn = new ConnectionOptions();
oConn.Authentication = AuthenticationLevel.PacketPrivacy;
oConn.Impersonation = ImpersonationLevel.Impersonate;

ManagementScope oMS = new ManagementScope(remoteComputer, oConn);
oMS.Connect();

ObjectQuery oQuery = new System.Management.ObjectQuery(_wmiQuery);
ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oMS,
oQuery);
ManagementObjectCollection oReturnCollection = oSearcher.Get();
foreach (ManagementObject oReturn in oReturnCollection) //Invalid
Query Exception here
{
//do stuff
}
Zinck74
2011-01-05 23:35:00 UTC
Permalink
Nevermind, I'm an idiot. :) Even though they are listed on the MS website as being like DomainDeny[], you don't actually use the square brackets in the WMI query. I still haven't actually gotten the data out of the arrays, but I assume I will just need to loop through the array to get the data I need.
Loading...