System.Management.ManagementException问题 [英] System.Management.ManagementException question
问题描述
我正在下面code
System.Management.ManagementClass wmiNetAdapterConfiguration = new System.Management.ManagementClass("Win32_NetworkAdapterConfiguration");
System.Management.ManagementObjectCollection wmiNetAdapters = wmiNetAdapterConfiguration.GetInstances();
Log.logInfo("Net adapters:" + wmiNetAdapters.get_Count());
和在一些机器上它是好的,并且在一些我收到以下错误:
and on some machines it is ok , and on some i am getting following error :
System.Management.ManagementException: Not found
at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode)
at System.Management.ManagementScope.InitializeGuts(Object o)
at System.Management.ManagementScope.Initialize()
at System.Management.ManagementObject.Initialize(Boolean getObject)
at System.Management.ManagementClass.GetInstances(EnumerationOptions options)
at System.Management.ManagementClass.GetInstances()
任何想法,为什么?
Any idea why ?
推荐答案
由提供的功能 System.Management
命名空间是依赖于的 WMI(Windows管理规范)服务。
我怀疑是WMI服务尚未开始被抛出该异常系统。
为了排除故障,您可以验证使用的管理工具 - >服务工具
如果这原来是这样,你可以用在code在尝试
- 抓
块使用<一个href="http://msdn.microsoft.com/en-us/library/system.serviceprocess.servicecontroller.aspx"><$c$c>ServiceController$c$c>类启动和停止相应的服务。
I suspect that the WMI service has not been started on the systems that are throwing that exception.
For troubleshooting purposes, you can verify that using the Administrative Tools -> Services utility.
If this turns out to be the case, you can wrap the code in a try
-catch
block and use the ServiceController
class to start and stop the appropriate service.
这篇关于System.Management.ManagementException问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!