Skip to content

Instantly share code, notes, and snippets.

@saibimajdi
Last active February 25, 2024 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save saibimajdi/749e2c715d95798637fadfde661802e2 to your computer and use it in GitHub Desktop.
Save saibimajdi/749e2c715d95798637fadfde661802e2 to your computer and use it in GitHub Desktop.
Get CPU ID & Motherboard Serial Number
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Text;
using System.Threading.Tasks;
namespace PCInformations
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Loading...");
Console.Write($"CPU ID= ");
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"{getCpuID()}");
Console.ResetColor();
Console.Write($"Motherboard Serial Number = ");
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"{getMotherBoardID()}");
Console.ResetColor();
Console.WriteLine("Press any key to close");
Console.ReadKey();
}
private static string getCpuID()
{
ManagementClass management = new ManagementClass("win32_processor");
ManagementObjectCollection managementObjectCollection = management.GetInstances();
foreach (var managementObject in managementObjectCollection)
{
var cpuid = managementObject.Properties["processorID"].Value.ToString();
return cpuid;
}
return "";
}
private static string getMotherBoardID()
{
string serial = "";
try
{
ManagementObjectSearcher mos = new ManagementObjectSearcher("SELECT SerialNumber FROM Win32_BaseBoard");
ManagementObjectCollection moc = mos.Get();
foreach (ManagementObject mo in moc)
{
serial = mo["SerialNumber"].ToString();
}
return serial;
}
catch (Exception) { return serial; }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment