Last active
February 25, 2024 16:29
-
-
Save saibimajdi/749e2c715d95798637fadfde661802e2 to your computer and use it in GitHub Desktop.
Get CPU ID & Motherboard Serial Number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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