首先需要添加一个system.management的引用,在添加引用选项卡。
using System.Management;
/// <summary>
/// 获取MAC地址
/// </summary>
/// <returns></returns>
public string GetNetCardMacAddress()
{
ManagementClass mc;
ManagementObjectCollection moc;
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>
/// C盘序列号
/// </summary>
/// <returns></returns>
public string GetDiskVolumeSerialNumber()
{
ManagementObject disk;
disk = new ManagementObject("win32_logicaldisk.deviceid=\"c:\"");
disk.Get();
return disk.GetPropertyValue("VolumeSerialNumber").ToString();
}
请发表评论