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

posted @ 2006-11-17 08:44  永不言败  阅读(3589)  评论(0编辑  收藏  举报