C# 获取本机CPU,硬盘等信息的代码
public string getCpuInfo() //读取CPU信息 { ManagementClass mobj = new ManagementClass("Win32_Processor"); ManagementObjectCollection moc = mobj.GetInstances(); foreach (ManagementObject mo in moc) { return mo.Properties["ProcessorId"].Value.ToString(); } return ""; } public string getHddInfo() //读取硬盘信息 { ManagementClass mobj = new ManagementClass("Win32_PhysicalMedia"); ManagementObjectCollection moc = mobj.GetInstances(); foreach (ManagementObject mo in moc) { return mo.Properties["SerialNumber"].Value.ToString(); } return ""; }