System.Management.ManagementException [英] System.Management.ManagementException

查看:389
本文介绍了System.Management.ManagementException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行以下代码:

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:找不到

System.Management.ManagementException: Not found

调用堆栈:

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

知道为什么吗?

推荐答案

System.Management 命名空间取决于 WMI(Windows管理规范)服务。

我怀疑在抛出该异常的系统上尚未启动WMI服务。

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.

如果确实如此,则可以将代码包装为 try - catch 块并使用 ServiceController 启动和停止适当的服务。

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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆