【C#】获取硬盘的型号,一般加密软件的手段
需要引用的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);