C#

Get CPU ID – Serial number using C#

Today we will see a simple function to retrieve local machine’s cpu id – serial number. We need the class ManagementObjectSearcher. To use this class we have to add a reference to System.Management namespace.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public String getCPUID()
{
	String cpuid = "";
	try
	{
		ManagementObjectSearcher mbs = new ManagementObjectSearcher("Select ProcessorID From Win32_processor");
		ManagementObjectCollection mbsList = mbs.Get();
 
		foreach (ManagementObject mo in mbsList)
		{
			cpuid = mo["ProcessorID"].ToString();
		}
		return cpuid;
	}
	catch (Exception) { return cpuid; }
}
}