日期:2014-05-18  浏览次数:20908 次

关于命名空间system.management引用的问题
我现在通过代码获取本机的MAC,百度了一下,得到一段代码,我引用了system.management后,还是提示
"错误 2 未能找到类型或命名空间名称“Management”(是否缺少 using 指令或程序集引用?) D:\JSJBOXHelp\JSJBOXHelpBack\Login.cs 162 13 JSJBOXHelpBack
"

代码如下
C# code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Management;


namespace JSJBOXHelpBack
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
        }

        private void Login_Load(object sender, EventArgs e)
        {
            string MoAddress = "";
            Management mc = new Management("Win32_NetworkAdapterConfiguration");
            ManagementObjectCollection moc = mc.GetInstances();
            foreach (ManagementObject mo in moc)
            {
                if ((bool)mo["IPEnabled"] == true)
                    MoAddress = mo["MacAddress"].ToString();
                mo.Dispose();
            }
        }
    }
}






------解决方案--------------------
项目-引用 右键选择 添加引用,选择 system.management引入dll