I need to get basic information about the computer's processor in a WPF application I'm writing.
Data such as "Intel(R) core(TM) 2 Quad CPU Q6600 @ 2.4GHz"
How do I do this?
I need to get basic information about the computer's processor in a WPF application I'm writing.
Data such as "Intel(R) core(TM) 2 Quad CPU Q6600 @ 2.4GHz"
How do I do this?
Some of what you're looking for is exposed by properties of the System.Environment
class. You might also be interested in the System.Windows.Forms.SystemInformation
class.
Use WMI
using System.Management;
private static string GetProcessorID()
{
ManagementClass mgt = new ManagementClass("Win32_Processor");
ManagementObjectCollection procs= mgt.GetInstances();
foreach ( ManagementObject item in procs)
return item.Properties["Name"].Value.ToString();
return "Unknown";
}
This information (and much, much more) is available via Windows Management Instrumentation (or WMI for short). It isn't technically tied to WPF. Please take a look at this article to get you started!
Use WMI to obtain the information needed, especially the classes in the System.Management namespace. First. add a reference to the System.Management assembly, then use code similar to this one:
ManagementClass wmiManagementProcessorClass = new ManagementClass("Win32_Processor");
ManagementObjectCollection wmiProcessorCollection = wmiManagementProcessorClass.GetInstances();
foreach (ManagementObject wmiProcessorObject in wmiProcessorCollection)
{
try
{
MessageBox.Show(wmiProcessorObject.Properties["Name"].Value.ToString());
}
catch (ManagementException ex)
{
// real error handling here
MessageBox.Show(ex.Message);
}
}