Today fast review of rules for querying for embedded object within another WMI object.
Basic WMI search query returns collection of
System.Management.ManagementObjectCollection. This collection contains a set of
System.Management.ManagementObject. Each of them has filled in only a subset of all possible properties. This are those, what are simple WMI data types (String, Int, Bool). When we want to retrieve complex Class based property, the embedded object is missing and the code returns NULL value.
To archieve filling in these object fields, there is class method called
This method is described here. It can be used for quick retrieval of single object, but also it is used during handling any modification of object.
The side effect is filling in the whole object including any embedded structured complex types instances.
Following code ilustrates the case:
// for kerberos konstrained delegation
ConnectionOptions wmiOptions = new ConnectionOptions();
wmiOptions.Authentication = AuthenticationLevel.PacketPrivacy;
wmiOptions.Impersonation = ImpersonationLevel.Impersonate;
// for connection to remote host
ManagementScope scope = new ManagementScope("\\\" + serverName + "\\root\\SMS\\Site_" + siteCode, wmiOptions);
// for performing query to wmi
WqlObjectQuery wmiQuery = new WqlObjectQuery(query);
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, wmiQuery);
// performing search itself
ManagementObjectCollection Colls = searcher.Get();
ManagementBaseObject rules = null;
ManagementObject coll = null;
//retrieving objects from collection, in this example we assume only one result
foreach (ManagementObject o in Colls)
coll = o;
// coll["CollectionRules"] == null
// after previous call it is filled in
rules = (ManagementBaseObject)o["CollectionRules"];