[问题记录.dotnet]取网卡信息报错"找不到"-WMI - Not found
来源:互联网 发布:2016淘宝618抢红包 编辑:程序博客网 时间:2024/04/30 12:46
异常:
System.Management.ManagementException: 找不到在 System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode)
在 System.Management.ManagementObject.Initialize(Boolean getObject)
在 System.Management.ManagementBaseObject.get_wbemObject()
在 System.Management.ManagementBaseObject.get_ClassName()
在 System.Management.ManagementClass.GetInstances(EnumerationOptions options)
现象:某台机器之前使用正常,突然报这个错。
其他机器均正常。
解决:
1. 确保服务“Windows Management Instrumentation”开启。2. 如果已经开启还是有问题,那么可能是WMI存储库损坏,需要重建WMI存储库。
要重建WMI存储库,(Win7等系统)步骤操作:
(如果是XP系统,参考 http://windowsxp.mvps.org/repairwmi.htm)
————————————–
1.开始->所有程序->附件,以管理员身份打开命令提示符command
2.停止WMI服务:net stop winmgmt
3.Repository目录改名备份:ren %windir%\System32\Wbem\Repository Repository_backup
4.重启WMI服务:net start winmgmt
5.运行 winmgmt /salvagerepository 尝试重建Repository
6.注册WMI组件:
cd /d %windir%\system32\wbem
for /f %%s in (‘dir /b *.dll’) do regsvr32 /s %%s
for /f %%s in (‘dir /b *.mof *.mfl’) do mofcomp %%s
wmiprvse /regserver
winmgmt /regserver
7.重新启动系统
8.重新安装自动更新成功
—————————————–
如果仍不成功,运行 %SystemRoot%\System32\Wbem\WbemTest.exe 测试WMI连接,点击连接,再次点击连接。如果仍然有连接错误,那么需要尝试全面的重建,运行下面的命令:
rundll32.exe setupapi,InstallHinfSection WBEM 132 %windir%\inf\wbemoc.inf
执行上面的命令后,可能会需要读取 Windodws 7/Windows 2008 R2 安装盘。
分析:
导致错误的代码段public static string GetNetworkCardInfo(){ ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"); ManagementObjectCollection moc2 = mc.GetInstances(); <span style="color:#ff0000;">//这一句抛出的异常</span> string netcard = string.Empty; foreach (ManagementObject mo in moc2) { if ((bool)mo["IPEnabled"] == true) { netcard = mo["MacAddress"].ToString(); mo.Dispose(); break; } mo.Dispose(); } return netcard;}原因:
System.Management 命名空间下的方式基本都是依赖WMI (Windows Management Instrumentation) 服务的,所以自然就联想到WMI的问题。然后去用工具或vbs脚本检验一下,基本就能确认了。
- [问题记录.dotnet]取网卡信息报错"找不到"-WMI - Not found
- zeppelin sql报错找不到表 Table not found
- 【WMI】WMI For C#/dotNet 用WMI获取系统信息
- WMI取不到信息
- selenium IDE ,明明存在元素,却找不到元素 ,报错Element not found
- SSH整合 项目启动突然报错 log4j listener 找不到jar包 class not found
- -bash:ls:command not found,执行命令总是报找不到
- -bash:ls:command not found,执行命令总是报找不到
- method initializationerror not found:JUnit4单元测试报错问题
- method initializationerror not found:JUnit4单元测试报错问题
- method initializationerror not found:JUnit4单元测试报错问题
- JUnit4单元测试报错问题 :method initializationerror not found
- JUnit4单元测试报错问题:method initializationerror not found
- method initializationerror not found:JUnit4单元测试报错问题
- JUnit报错method initializationerror not found的相关问题
- SpringBoot单元测试报错问题method initializationerror not found:JUnit4
- method initializationerror not found:JUnit4单元测试报错问题
- 记录服务器网卡报错
- Lua_第17 章 数学库
- Ubuntu 14.04环境下使用QQ
- Git status,diff
- 语音识别
- 16年第一个电面
- [问题记录.dotnet]取网卡信息报错"找不到"-WMI - Not found
- c++第二次上机实验作业
- 二叉树构建,先序,中序,后序遍历(以及非递归实现),广度优先遍历
- Redis常用命令
- c++第二次上机实验
- $.each()的使用
- activity和fragment的通信
- 关于TCP流模式与UDP数据报模式的区别
- c++实验二编程分段函数