C# 98系统下如何获取 mac 地址?

解决方案 »

  1.   


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

  2.   

    上面那个只能够获取 2000 以上系统的 mac ,
    在98 系统上抛异常,
    mc = new ManagementClass("Win32_NetworkAdapterConfiguration"); 这一行代码有问题
      

  3.   

    补充:要加上usingusing System.Management;
      

  4.   

    GetMAC命令可以直接获取MAC地址,在C#里面调用DOS ,运行GetMAC就可以得到了..
      

  5.   

     98 下面调用不了 DOS ,这个也试了的,
    在 xp 上面可以获取,在 98 上获取不了!
      

  6.   

    调用DOS命令将信息独到txt文本中。
            public  string RunDosCommand()//运行DOS命令
            {
                Process process = new Process();
                process.StartInfo.FileName = "cmd.exe";
                process.StartInfo.UseShellExecute = false;//不使用系统外壳程序启动
                process.StartInfo.RedirectStandardInput = true;
                process.StartInfo.RedirectStandardOutput = true;//重定向输出,而不是默认的显示在dos控制台上
                process.StartInfo.RedirectStandardError = true;
                process.StartInfo.CreateNoWindow = false;//创建窗口
                process.Start();
                string Command = "";
                for (int i = 0; i < dtServer.Rows.Count; i++)
                {
                    Command = "getmac >>C:\MAC.txt";
                    process.StandardInput.WriteLine(Command);
                }
                process.StandardInput.WriteLine("exit");
                return process.StandardOutput.ReadToEnd();
            }
    再重txt文本中读取不知道能不能实现。
      

  7.   

    98下都不能调用DOS???
    怎么会在98 下要获取MAC啊