我正在下面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在尝试
- 抓
块使用ServiceController类启动和停止相应的服务。
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.