C#获取电脑硬盘,网卡,CPU的序列号

我实验了还可以,但是我只是截取了部分代码,见下面:

private void button1_Click(object sender, EventArgs e)
{
string cpuInfo = "";//cpu序列号
ManagementClass cimobject = new ManagementClass("Win32_Processor");
ManagementObjectCollection moc = cimobject.GetInstances();
foreach (ManagementObject mo in moc)
{
cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
this.txtcpu.Text = "cpu序列号:" + cpuInfo.ToString();
}
//获取硬盘ID
String HDid;
ManagementClass cimobject1 = new ManagementClass("Win32_DiskDrive");
ManagementObjectCollection moc1 = cimobject1.GetInstances();
foreach (ManagementObject mo in moc1)
{
HDid = (string)mo.Properties["Model"].Value;
this.txtharddisk.Text = "硬盘序列号:" + HDid.ToString();
}

//获取网卡硬件地址 9558821702001755616


ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc2 = mc.GetInstances();
foreach (ManagementObject mo in moc2)
{
if ((bool)mo["IPEnabled"] == true)
this.txtic.Text = "MAC address/t{0}" + mo["MacAddress"].ToString();
mo.Dispose();
}
}

注意添加一个引用:System.Management.dll


你可能感兴趣的:(cpu)