Using WMI in the final analysis is access to WMI classes, and finding the right classes is a key step. I've been worried about not finding the right class and namespace. Do you have such a problem, too?
Class hierarchy
WMI's classes are organized in namespaces and inheritance hierarchies, and are in a tree-shaped structure. The root of the namespace is root, and there are more than 10 namespaces underneath it, most commonly root\cimv2. Namespace information is stored in the static class __namespace class, and to query all namespaces under the current namespace, you can view instances of the __namespace class. The following are the namespaces that are queried on my machine using PowerShell:
Copy Code code as follows:
PS c:\users\idsswtt> get-wmiobject-class __namespace-namespace Root | Select Name
Name
----
Subscription
DEFAULT
cimv2
Cli
Nap
MicrosoftIISv2
Security
Smsdm
Ccmvdi
Rsop
Webadministration
Ccm
Wmi
Directory
Policy
Virtualization
Interop
Hardware
ServiceModel
Microsoft
Aspnet
For more information about namespaces, you can write a recursive script to get it, or start with WMI (ii): How to use the WMI CIM Studio Tools mentioned in WMI.
Common WMI Classes
There are hundreds of classes in the WMI architecture. Only a fraction of what we often use. Some of these are used to query instances, and others to query the schema of the class. In addition to the __namespace class mentioned above, we will also use the __Win32Provider class to query which providers are available in the current system. These two classes are system classes.
In addition, there are two classes of WMI classes that we often use: the Cim_* class and the Win32_* class. The former is a core class of WMI and a common class, often referred to as the CIM core classes and public classes. The latter is the Win32 extension class, and we query the instance more in the Win32 extension class. such as Win32_Product, Win32_LogicalDisk and so on.
WMI Class lookup manual?
It is a pity that so far. I didn't find a handy WMI class lookup manual. But on the Microsoft MSDN website, there is a classification. We can do the query according to this classification. Here are a few links I often use, posted here, I hope you can use.
WMI Reference
Win32 Classes
WMI Providers
Conclusion
Read the above I wrote these things, if you still can't find the class you want, then you can only blame Microsoft. I think Microsoft is still doing too little for WMI, at least in the class query. Until Microsoft invests more in WMI, we can only rely on experience and search engines to find the right class.