(一).說明
取得設備網卡的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();
}
}
}