A tutorial on querying system information from Windows Management Instrumentation (WMI) in .NET.
Working on a library needing the ability to detect if it is executing on a virtual environment I resorted to using WMI to create my red pill functions. Finding great use out of WMI I have decided to create this simple tutorial for others to reference and learn from.
WMI is capable of returning information about a Windows system and the software that runs on it by refering to a specific namespace, class, and property. For example, the root\CIMV2 namespace contains several classes pertaining to the system's current hardware configuration such as the motherboard, CPU, RAM, NIC (Network Interface Card), storage, etc.. Even specific BIOS and hardware vendor/manufacturer information can be queried from WMI as well. You can find new namespaces and their classes through PowerShell, WMI Code Creator, or online. For a list of classes you will have to do the same as above as if you were looking for a new namespace.
The command structure is [class] [property]
. So we will type in and execute win32_processor name
which for me returns:
Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz.
You can find more classes and properties with their descriptions under the root\CIMV2 namespace here.