c# – ‘ManagementClass’不存在于命名空间’System.Management
发布时间:2020-12-15 03:59:54 所属栏目:百科 来源:网络整理
导读:嗨,我正在使用这个方法获取mac地址 public string GetMACAddress(){ System.Management.ManagementClass mc = default(System.Management.ManagementClass); ManagementObject mo = default(ManagementObject); mc = new ManagementClass("Win32_NetworkAdap
嗨,我正在使用这个方法获取mac地址
public string GetMACAddress() { System.Management.ManagementClass mc = default(System.Management.ManagementClass); ManagementObject mo = default(ManagementObject); mc = new ManagementClass("Win32_NetworkAdapterConfiguration"); ManagementObjectCollection moc = mc.GetInstances(); foreach (var mo in moc) { if (mo.Item("IPEnabled") == true) { return mo.Item("MacAddress").ToString(); }else return null; } } 但我收到这个错误 Compiler Error Message: CS0234: The type or namespace name 'ManagementClass' does not exist in the namespace 'System.Management' (are you missing an assembly reference?) 我要做什么来解决它? 谢谢 解决方法
您需要在项目中使用
add a reference to System.Management.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |