c#获取MAC地址 硬盘序列号

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

你可能感兴趣的:(mac)