NET获取硬盘序列号的几个方法
NET获取硬盘序列号的几个方法
NET获取硬盘序列号的几个方法.txt37真诚是美酒,年份越久越醇香浓烈;真诚是焰火,在高处绽放才愈显美丽;真诚是鲜花,送之于人,手有余香。最近作软件注册,收集了很多.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
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//在Vista下面失败
ArrayList hdCollection = new ArrayList();
ManagementObjectSearcher searcher = new
ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");
foreach(ManagementObject wmi_HD in searcher.Get())
{
HardDrive hd = new HardDrive();
hd.Model = wmi_HD["Model"].ToString();
hd.Type = wmi_HD["InterfaceType"].ToString();
hdCollection.Add(hd);
}
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;
}
// Display available hard drives
foreach(HardDrive hd in hdCollection)
{
Console.WriteLine("Model\t\t: " + hd.Model);
Console.WriteLine("Type\t\t: " + hd.Type);
Console.WriteLine("Serial No.\t: " + hd.SerialNo)
;
Console.WriteLine();
}
// Pause application
Console.WriteLine("Press [Enter] to exit...");
Console.ReadLine();
}
}
你可能喜欢
- vc硬盘物理序列号
- chanel序列号年份
- gt+designer3序列号
- 硬盘物理序列号hemfanings
- nero2014序列号
- iphone4序列号
- 查看硬盘物理序列号
- CHANEL——展示分析29页
- chanel公共关系79页
- chanel调研报告9页
- Chanel香奈儿香水17页
- 缔造中国的夏奈尔24页
- 剁手时间到!Chanel线上商城如期而至,引领网上购物新潮流4页
- WPS序列号,够用一年1页
- 梦幻西游迎新序列号1页
- 正确获取硬盘序列号6页
- 英雄三国新秀序列号1页
- A-11 设备序列号清单1页
- 4、车牌序列号设计3311页
- 怎样用vc获取硬盘物理序列号15页
- 获得cpu,硬盘的物理序列号 C#2页
- VB获取硬盘物理序列号源码9页
- 如何用WD修改西部硬盘物理序号2页
- 纯VB代码取得硬盘的物理序列号6页
- Delphi_读取硬盘的物理序列号2页
- NERO8安装序列号1页
- 刻录软件序列号3页
- nero插件序列号3页
- 刻录软件序列号1页
- nero7安装序列号4页
- nero7安装序列号1页