需要引用的DLL:System.Management 需要使用的命名空间:using System.Management; //需要用到的类: //ManagementObject:WMI对象 //ManagementObjectSearcher:查询管理信息 //ManagementObjectSearcher.Get("查询语句"),返回结果集合 //PropertyData来的value属性 string hard = ""; //创建ManagementObjectSearcher对象 ManagementObjectSearcher mos = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia"); ManagementObjectCollection moc = mos.Get(); //信息集合 foreach (ManagementObject k in moc) { hard += k["SerialNumber"].ToString().Trim(); } Console.WriteLine(hard);
时间: 2024-10-28 12:53:27