如题

解决方案 »

  1.   

    public static string GetMac()
    {
    System.Management.ManagementClass mc = new System.Management.ManagementClass("Win32_NetworkAdapterConfiguration");
    System.Management.ManagementObjectCollection moc = mc.GetInstances();
    System.Text.StringBuilder sb = new System.Text.StringBuilder();
    foreach(ManagementObject mo in moc)
    {
    if((bool)mo["IPEnabled"] == true)
    sb.Append(mo["MacAddress"].ToString());
    mo.Dispose();
    }
    return(sb.ToString());
    }
      

  2.   

    一个偷懒的方法:System.Diagnostics.Process p=new System.Diagnostics.Process();
    p.StartInfo.CreateNoWindow=true;
    p.StartInfo.UseShellExecute=false;
    p.StartInfo.RedirectStandardOutput=true;
    p.StartInfo.FileName="ipconfig";
    p.StartInfo.Arguments="/all";
    p.Start();
    p.WaitForExit();
    string s=p.StandardOutput.ReadToEnd();
    MessageBox.Show(s.Substring(s.IndexOf("Physical Address. . . . . . . . . :")+36,17));嘿嘿调用ipconfit /all产生的结果。
      

  3.   

    请问,在第一个方法里的System.Management.ManagementClass的命名空间是什么啊
      

  4.   

    命名空间就是System.Management
    不过需要在项目中添加对System.Management.dll的引用