C#获取硬盘序列号

时间:2021-11-16 17:20:57
            //创建ManagementObjectSearcher对象
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");
String strHardDiskID = null;//存储磁盘序列号
//调用ManagementObjectSearcher类的Get方法取得硬盘序列号
foreach (ManagementObject mo in searcher.Get())
{
strHardDiskID = mo["SerialNumber"].ToString().Trim();//记录获得的磁盘序列号
break;
}
label1.Text = "硬盘序列号: "+strHardDiskID;//显示硬盘序列号