admin管理员组文章数量:1531979
2024年6月4日发(作者:)
最近作软件注册,收集了很多.NET相关的获取硬盘物理序列号的方法,主要分为使用WMI方
式和API方式。但这些方法均可能有问题。
1,使用WMI方式,有的机器根本取不到硬盘序列号,有的方式在Vista下面会报错。
常用的使用WMI的方式主要有下面一些方式:
class HardDrive
{
private string model = null;
private string type = null;
private string serialNo = null;
public string Model
{
get {return model;}
set {model = value;}
}
public string Type
{
get {return type;}
set {type = value;}
}
public string SerialNo
{
get {return serialNo;}
set {serialNo = value;}
}
}
class TestProgram
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
//在Vista下面失败
ArrayList hdCollection = new ArrayList();
ManagementObjectSearcher searcher = new
ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");
foreach(ManagementObject wmi_HD in ())
{
HardDrive hd = new HardDrive();
= wmi_HD["Model"].ToString();
= wmi_HD["InterfaceType"].ToString();
(hd);
}
searcher = new
ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");
int i = 0;
foreach(ManagementObject wmi_HD in ())
{
// get the hard drive from collection
// using index
HardDrive hd = (HardDrive)hdCollection[i];
// get the hardware serial no.
if (wmi_HD["SerialNumber"] == null)
No = "None";
else
No = wmi_HD["SerialNumber"].ToString();
++i;
}
// Display available hard drives
foreach(HardDrive hd in hdCollection)
{
ine("Modeltt: " + );
ine("Typett: " + );
ine("Serial No.t: " + No);
ine();
}
// Pause application
ine("Press [Enter] ");
ne();
}
}
版权声明:本文标题:NET获取硬盘序列号的几个方法 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1717460530a574480.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论