windows System.Management.ManagementException:未找到

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7165174/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 17:55:18  来源:igfitidea点击:

System.Management.ManagementException: Not found

c#.netwindows

提问by Zak

I am running the following code:

我正在运行以下代码:

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

which is throwing this exception:

这是抛出这个异常:

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()

I went to check on the running services on Windows XP and found that Windows Management Instrumentation service has a status of 'Started'. I tried restarting the service but that didn't do any good. I then tried to get the status of this service from within my running code using the ServiceController class:

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

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

wmiStatus evaluates to 'Running'.

wmiStatus 评估为“正在运行”。

I have seen this error on only one of multiple machines running the same software. What's peculiar is that the machine was running smoothly for months, and then suddenly started showing this error.

我只在运行相同软件的多台机器中的一台上看到过这个错误。奇怪的是,机器运行了几个月,然后突然开始显示这个错误。

Any clue as to what might be causing this?

关于可能导致这种情况的任何线索?

采纳答案by Zak

The solution was to repair WMI on Windows XP. I don't have the detailed step by step fix (I'm not the one who implemented the fix), but my understanding is that a repository related to this service can get corrupted and there's a Windows utility that can repair it. There are several online resources on how to do this.

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

回答by Martin Rasmusson

I have also run into this issue. Here is one of the previously mentioned online resources explaining how one can fix WMI: http://windowsxp.mvps.org/repairwmi.htm

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

The method of repairing seems to be different between different versions of Windows as explained on that page.

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

I had this problem on none of these versions, but on Windows Embedded Standard 2009. Since Windows XP Service Pack 2 is closest related to the listed OSes, that is the one I used:

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

For Windows XP Service Pack 2

Click Start, Run and type the following command:

rundll32 wbemupgd, UpgradeRepository

This command is used to detect and repair a corrupted WMI Repository. The results are stored in the setup.log (%windir%\system32\wbem\logs\setup.log) file.

对于 Windows XP Service Pack 2

单击开始,运行并键入以下命令:

rundll32 wbemupgd, UpgradeRepository

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