WMI Namespace and __Genus property confusion

My question is less to do with scripting as a whole, and more to do with WMI in a general sense. I've been writing a program in C# to scavenge information out of WMI as a project (I know many great tools out there exist already, but this is both for learning and custom tailored to an environment I manage), and I've come across a few oddities. Currently tripping me up is the following snippet below:

using System.Management;

ManagementClass managementClass = new ManagementClass(new ManagementPath(@"\\" + pHostName + @"\root\" + pNameSpace));

EnumerationOptions enumOptions = new EnumerationOptions();
enumOptions.EnumerateDeep = false;

foreach(ManagementObject wmiClass in managementClass.GetSubclasses())
{
    Console.WriteLine(wmiClass["__Class"].ToString());
}

Given the definition of System.Management.ManagementClass under both the MSDN documentation and the VS Documentation, which I'll paraphrase pretty heavily to say it represents a CIM class, and the definition for the GetSubclasses() method which returns a collection of all subclasses under a class (under a class being the key phrase there), the only logical conclusion I can make as to why this works is that a Namespace in WMI is actually an instance of a class, which sounds incredibly wrong.

Are Namespaces actually instances of classes in WMI? On another note, what's the deal with the __genus property of classes? Why is the following a perfectly acceptable WQL:

select * from meta_class where __class like "%win32%" and __superclass like "%process%"

but this is not:

select * from meta_class where __class like "%win32%" and __genus is 2
select * from meta_class where __genus = 1

Neither of the above work, but are both valid and populated properties of classes when a query like the first is performed.

TL;DR; (but I hope you do Read) Are WMI Namespaces actually instances of a higher class? Additionally, why can I query something like __superclass, but not __genus?

Sincerely,

Really confused

  • Edited by Inkrement 14 hours 13 minutes ago tl;dr
September 2nd, 2015 12:45pm

Unfortunately filters do not work with classes.  They only work with class instances.

Free Windows Admin Tool Kit Click here and download it now
September 2nd, 2015 12:59pm

I'm a little confused by this answer. Are __class and __superclass  not defined as filters as well? Because querying based on that works fine, only __genus seems to have issues.

September 2nd, 2015 1:06pm

Classes of all kinds cannot be filtered. Filters only apply to instances.  You can have an instance of a class bot not of a formal class.

When you enumerate "meta_class" you are getting all classes that are in that portion of the schema. It is similar to using "GWMI -List *"

Download the SDK and go through the WMI tutorial.

WMI is CIM.  CIM allows vendors to customize the schema.  MS has been one of the busiest members of the DMTF.   PowerShell and Windows now use all CIM designations.  The new SDK documents the CIM support which is a standardized rethink of the CIM implementation in  Windows.

For more information and links to resources post in the Windows Management forum.

Free Windows Admin Tool Kit Click here and download it now
September 2nd, 2015 1:56pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics