Hello,
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 Get()
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | // 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 coll.Get(); // after previous call it is filled in rules = (ManagementBaseObject[])o["CollectionRules"]; } |