Skip to content

Instantly share code, notes, and snippets.

@maldevel
Last active January 16, 2016 06:31
Show Gist options
  • Save maldevel/a4e3f9c8e882abfe81ac to your computer and use it in GitHub Desktop.
Save maldevel/a4e3f9c8e882abfe81ac to your computer and use it in GitHub Desktop.
Retrieve Processors Information
using System;
using System.Management;
namespace coreinfo
{
class Program
{
static void Main(string[] args)
{
PrintCoreInfo();
}
static void PrintCoreInfo()
{
try
{
string cpuName = string.Empty;
string query = "SELECT * FROM Win32_Processor";
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(query))
{
foreach (ManagementObject mObject in searcher.Get())
{
Console.WriteLine("Physical CPU: " + mObject["Name"].ToString());
Console.WriteLine("Logical CPU(s): " + mObject["NumberOfLogicalProcessors"].ToString());
Console.WriteLine("Core(s): " + mObject["NumberOfCores"].ToString());
}
}
}
catch
{
Console.WriteLine("Retrieving core information failed!");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment