![]() |
General Reading »
Hardware & System »
WMI
Intermediate
License: The Code Project Open License (CPOL)
Using WMI to retrieve processor information in C#By radialronnieThis article demonstrates how to use WMI (Windows Management Instrumentation) in C#, to retrieve several bits of information about the processor. |
C#, Windows, Dev
|
||||||||
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
This article demonstrates how to use WMI (Windows Management Instrumentation) in C#, to retrieve several types of information about the processor, such as the CPU clock speed, Voltage, Manufacturer, and other properties. Included in the first .zip is the executable polls your system for all the implemented properties. The bench-marker looks like this:
It seems that WMI is an unknown concept to many beginners and maybe it intimidates the somewhat more advanced ones. On the MSDN forums there are several questions on how to get CPU/Harddrive information. In this article I will demonstrate how to get a handful of CPU related properties, beginning on what hopefully will become a series of WMI articles/wrappers in the near future.
To use the wrapper, download the .cs file and place it in your application's solution folder: WMI_ProcessorInformationWrapper.zip - 901 B.
Next add a using reference to the namespace:
using WMI_ProcessorInformation;
the last step is to call one of the static methods like this:
WMI_Processor_Information.GetCpuManufacturer() ;
That's really all that there is to using the wrapper, so now lets take a tiny peek at some of what goes on behind the scenes. Most of the methods look like this one:
public static string GetCpuManufacturer()
{
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_Processor");
foreach (ManagementObject queryObj in searcher.Get())
{
return queryObj["Manufacturer"].ToString();
}
}
catch (Exception e)
{
return null;
}
return null;
}
This article was not meant to teach WMI but rather to present a conveinient way of getting CPU information through the wrapper. To learn more about WMI check out some the great article here on codeproject: CodeProject Search for WMI
WMI is very powerfull and can be used to get the properties of many different system components such as:
| Harddrive (total space, space remaining) |
| Battery (on a laptop) |
| Screensavers (executable path, timeout ) |
| Wallpaper (image display mode, path to image) |
| hardware refridgeration!(fan RPM,etc), |
| User Account (User name, User's time zone) |
P.S. As this is my first article please cut me at least a little slack, but I am NOT opposed to constructive critisism and we'll have an article version at 2.5 before you know it.
V 0.9 ~Initial release.
| You must Sign In to use this message board. | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 23 May 2008 Editor: |
Copyright 2008 by radialronnie Everything else Copyright © CodeProject, 1999-2009 Web09 | Advertise on the Code Project |