System.Management.ManagementException:未找到

时间:2011-08-23 17:34:58

标签: c# .net windows

我正在运行以下代码:

ManagementClass oMClass = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection colMObj = oMClass.GetInstances();

抛出此异常:

System.Management.ManagementException: Not found 
at System.Management.ThreadDispatch.Start()
at System.Management.ManagementScope.Initialize()
at System.Management.ManagementObject.Initialize(Boolean getObject)
at System.Management.ManagementClass.GetInstances(EnumerationOptions options)
at System.Management.ManagementClass.GetInstances()

我去检查Windows XP上正在运行的服务,发现Windows Management Instrumentation服务的状态为“已启动”。我尝试重新启动服务,但这没有任何好处。 然后,我尝试使用ServiceController类从我正在运行的代码中获取此服务的状态:

ServiceController wpiService = new ServiceController();
wpiService.ServiceName = "Winmgmt";
string wmiStatus = wpiService.Status.ToString();
MessageBox.Show("WMI status= " + wmiStatus);

wmiStatus评估为“正在运行”。

我在运行相同软件的多台计算机中只有一台出现此错误。奇怪的是机器运行了几个月,然后突然开始出现这个错误。

有关可能导致此问题的任何线索?

2 个答案:

答案 0 :(得分:4)

我也遇到过这个问题。以下是前面提到的在线资源之一,解释了如何修复WMI: http://windowsxp.mvps.org/repairwmi.htm

修复方法在不同版本的Windows之间似乎有所不同,如该页面所述。

我在这些版本上都没有这个问题,但是在Windows Embedded Standard 2009上。由于Windows XP Service Pack 2与列出的操作系统最相关,所以我使用的是:

  

对于Windows XP Service Pack 2

     

单击“开始”,“运行”,然后键入以下命令:

     

rundll32 wbemupgd,UpgradeRepository

     

此命令用于检测和修复损坏的WMI存储库。结果存储在setup.log(%windir%\ system32 \ wbem \ logs \ setup.log)文件中。

答案 1 :(得分:3)

解决方案是在Windows XP上修复WMI。我没有详细的一步一步修复(我不是实现修复的人),但我的理解是与此服务相关的存储库可能会损坏,并且有一个可以修复它的Windows实用程序。有几个关于如何执行此操作的在线资源。