BillyPilgrim
BillyPilgrim

Reputation: 551

Using WPF/C# to get information about the processor

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?

Upvotes: 1

Views: 3618

Answers (4)

Paul Creasey
Paul Creasey

Reputation: 28864

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";
    }

Upvotes: 4

Jim Brissom
Jim Brissom

Reputation: 32959

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);
    }
}

Upvotes: 0

Igal Tabachnik
Igal Tabachnik

Reputation: 31548

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!

Upvotes: 1

Jim Mischel
Jim Mischel

Reputation: 134045

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.

Upvotes: 0

Related Questions