(一).说明
取得设备网卡的mac地址和硬盘的卷标号
(二).图片示例
(三).代码
using system;
using system.management;namespace netcard
{
/// <summary>
/// 读取设备
/// </summary>
public class run
{
private managementclass mc;
private managementobjectcollection moc;
private managementobject disk;
public run()
{}
/// <summary>
/// 取得设备网卡的mac地址
/// </summary>
public string getnetcardmacaddress()
{
mc = new managementclass("win32_networkadapterconfiguration");
moc = mc.getinstances();
string str = "";
foreach(managementobject mo in moc)
{
if((bool)mo["ipenabled"] == true)
str = mo["macaddress"].tostring();
}
return str;
}
/// <summary>
/// 取得设备硬盘的卷标号
/// </summary>
/// <returns></returns>
public string getdiskvolumeserialnumber()
{
mc = new managementclass("win32_networkadapterconfiguration");
disk = new managementobject("win32_logicaldisk.deviceid=/"c:/"");
disk.get();
return disk.getpropertyvalue("volumeserialnumber").tostring();
}
}
}
(四).示例下载
http://www.cnblogs.com/files/chengking/netcard.rar