c#提取本机的硬盘序列号
展开全部
public static List<string> GetHDIds()
{
List<string> hdIds = new List<string>();
try
{
//ManagementClass cimobject = new ManagementClass("Win32_DiskDrive");
ManagementClass cimobject = new ManagementClass("Win32_PhysicalMedia");
ManagementObjectCollection moc = cimobject.GetInstances();
foreach (ManagementObject mo in moc)
{
//String HDid = (string)mo.Properties["Model"].Value.ToString();//获取的是硬盘名称
String HDid = (string)mo.Properties["SerialNumber"].Value.ToString();
if (!string.IsNullOrEmpty(HDid))
{
hdIds.Add(HDid);
}
}
return hdIds;
}
catch (Exception r)
{
hdIds.Add("无法获得硬盘信息!");
MessageBox.Show("硬盘错误信息:" + r.Message);
return hdIds;
}
}
{
List<string> hdIds = new List<string>();
try
{
//ManagementClass cimobject = new ManagementClass("Win32_DiskDrive");
ManagementClass cimobject = new ManagementClass("Win32_PhysicalMedia");
ManagementObjectCollection moc = cimobject.GetInstances();
foreach (ManagementObject mo in moc)
{
//String HDid = (string)mo.Properties["Model"].Value.ToString();//获取的是硬盘名称
String HDid = (string)mo.Properties["SerialNumber"].Value.ToString();
if (!string.IsNullOrEmpty(HDid))
{
hdIds.Add(HDid);
}
}
return hdIds;
}
catch (Exception r)
{
hdIds.Add("无法获得硬盘信息!");
MessageBox.Show("硬盘错误信息:" + r.Message);
return hdIds;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询