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();

}

}

本文标签: 硬盘方法序列号获取软件