读取Sata硬盘序列号c# [英] Read Sata Harddisk Serial No. c#
本文介绍了读取Sata硬盘序列号c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用c#.net读取sata硬盘序列号
How to Read Sata Harddisk Serial No. using c#.net
推荐答案
使用Win32_PhysicalMedia系统信息,我们可以将序列号获取为:
Using Win32_PhysicalMedia system info, we can get the serial number as:
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");
int i = 0;
foreach(ManagementObject wmi_HD in searcher.Get())
{
// get the hard drive from collection
// using index
HardDrive hd = (HardDrive)hdCollection[i];
// get the hardware serial no.
if (wmi_HD["SerialNumber"] == null)
hd.SerialNo = "None";
else
hd.SerialNo = wmi_HD["SerialNumber"].ToString();
++i;
}
您也可以尝试以下方法:
You can also try this:
public static string HardDiskID()
{
ManagementClass partionsClass = new ManagementClass("Win32_LogicalDisk");
ManagementObjectCollection partions = partionsClass.GetInstances();
string hdd = string.Empty;
foreach (ManagementObject partion in partions)
{
hdd = Convert.ToString(partion["VolumeSerialNumber"]);
if (hdd != string.Empty)
return hdd;
}
return hdd;
}
如果您想要一个可靠的解决方案来读取硬盘序列号,可以尝试使用此商用产品
http://www.devlib.net/getdiskserial.htm [
If you want a robust solution to read Hard disk serial number, you can try this commerical product
http://www.devlib.net/getdiskserial.htm[^]
这篇关于读取Sata硬盘序列号c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文