通过 ManagementObjectSearcher 查询Win32_PhysicalMedia,然后使用 ManagementObject 遍历对象,提取中间的SerialNumber值,该值即为 物理硬盘序列号
//获取物理硬盘序列号
public string GetHardDiskSerialNumber()
{
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");
string sHardDiskSerialNumber = "";
foreach (ManagementObject mo in searcher.Get())
{
sHardDiskSerialNumber = mo["SerialNumber"].ToString().Trim();
break;
}
return sHardDiskSerialNumber;
}
catch
{
return "";
}
}
运行结果: