系统管理.管理异常

发布于 2024-10-21 04:55:35 字数 984 浏览 2 评论 0原文

我正在运行以下代码:

System.Management.ManagementClass wmiNetAdapterConfiguration = new System.Management.ManagementClass("Win32_NetworkAdapterConfiguration");
System.Management.ManagementObjectCollection wmiNetAdapters = wmiNetAdapterConfiguration.GetInstances();
Log.logInfo("Net adapters:" + wmiNetAdapters.get_Count());

在某些机器上它没问题,在某些机器上我收到以下错误:

System.Management.ManagementException:未找到

调用堆栈:

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

知道为什么吗?

I am running following 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

Call stack:

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

柳若烟 2024-10-28 04:55:35

我遇到了类似的问题,因为 WMI 文件以某种方式损坏了。

修复:

  1. 以管理员身份运行 cmd
  2. 键入“cd wbem”并按 Enter
  3. 键入“dir /b *.mof *.mfl | findstr /v /i 卸载> moflist.txt & for /F %s in (moflist.txt) do mofcomp %s”并按 Enter 键。

这应该可以解决 WMI 文件损坏问题。

I had the similar issue caused because WMI files got corrupted somehow.

Fix:

  1. Run cmd as Administrator
  2. Type "cd wbem" and hit Enter
  3. Type “dir /b *.mof *.mfl | findstr /v /i uninstall > moflist.txt & for /F %s in (moflist.txt) do mofcomp %s” and hit Enter.

This should fix WMI file corruption issue.

酒中人 2024-10-28 04:55:35

System.Management 命名空间提供的功能 依赖于 WMI (Windows Management Instrumentation)服务。

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

为了进行故障排除,您可以使用管理工具 → 服务实用程序进行验证。

如果情况确实如此,您可以将代码包装在 try-catch 块中,并使用 ServiceController 启动和停止相应的服务。

The functionality provided by the System.Management namespace is dependent upon the WMI (Windows Management Instrumentation) service.

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.

各自安好 2024-10-28 04:55:35

我们刚刚遇到了同样的问题,并按照下面链接的帖子一步步操作,并成功解决了问题。

https:// answers.microsoft.com/en-us/windows/forum/all/systemmanagementmanagementexception-invalid/74ac22c7-509d-42a5-9f7f-2686dc87b7b2

基本上,打开计算机管理并在左侧边栏中
转到服务和应用程序下拉菜单并转到 WMI
控制。然后看右边的栏,点击更多操作
然后是属性。如果你和我有同样的错误,你会
看到这里。我尝试执行“从上次备份恢复”,结果成功了
有一些错误。然后我点击“立即恢复”...我没有
备份,但我看到备份文件称为“*.rec 文件”。我
转到 Windows 搜索并搜索 *.rec 并在其中找到一个
C:\Windows\System32\wbem 。它被称为损坏的.rec 所以我没有
抱有很大的希望,似乎也想到了同样的事情
消息如前。所以我继续四处寻找直到我
最终回到WMI控制并发现它不再
显示名称空间错误,但我的系统规格。看到这个之后我
打开控制我的笔记本电脑和 IT 灯光的软件
打开。我终于能够转动我那该死的讨厌的笔记本电脑了
灯灭了。之后我对 WMI 进行了备份,现在我将制作一个
系统还原点。

We just experienced the same problem and followed the below linked post step by step and were able to fix the problem successfully.

https://answers.microsoft.com/en-us/windows/forum/all/systemmanagementmanagementexception-invalid/74ac22c7-509d-42a5-9f7f-2686dc87b7b2

Basically, Open up Computer management and in the sidebar on the left
side go to the services and application drop menu and go to WMI
control. Then look at the bar on the right and click on more actions
and then properties. If you are having the same error as me you will
see it here. I tried doing the 'restore from last backup' and it came
up with some errors. Then I clicked on 'Restore now'... I had no
backups but I saw that the backup files are called '*.rec files'. I
went to windows search and searched *.rec and it found one in
C:\Windows\System32\wbem . It was called corrupted.rec so I didn't
hold much hope, and it seemed as though it came up with the same
message as before. So I continued looking around and stuff until I
eventually went back to WMI control and saw that it no longer
displayed the namespace error but my system spec. After I saw this I
opened the software that controls the lights for my laptop and IT
OPENED. I have finally been able to turn my god damn obnoxious laptop
lights off. After this I made a backup for WMI and I will now make a
system restore point.

陌路黄昏 2024-10-28 04:55:35

WMI 服务正在为我运行,并且我使用的是管理员帐户。

当我使用 rsconfig.exe 运行命令时,我得到了完全相同的错误和堆栈跟踪,例如

cd C:\Program Files (x86)\Microsoft SQL Server\130\Tools\Binn\

rsconfig.exe -c -s sqlserver\instance -d dbName -a SQL -u user -p pass

我做错的是实例名称有自己的参数 -i 和这修复了它:

rsconfig.exe -c -s sqlserver -i instance -d dbName -a SQL -u user -p pass

要检查预期的参数,请运行:

rsconfig.exe /?

更新:

这实际上是不正确的,如果您查看预期的参数,它会指出服务器名称也必须包含实例名称,您不能包含引号,如果实例名称包含 $ 符号,您可能需要对其进行转义,请参阅此处了解更多信息:https://stackoverflow。 com/a/56370766/495455

The WMI Service was running for me and I was using a Administrator account.

I got the exact same error and stacktrace when I was running a command using rsconfig.exe, eg

cd C:\Program Files (x86)\Microsoft SQL Server\130\Tools\Binn\

rsconfig.exe -c -s sqlserver\instance -d dbName -a SQL -u user -p pass

What I was doing wrong was the instance name has its own argument -i and this fixed it:

rsconfig.exe -c -s sqlserver -i instance -d dbName -a SQL -u user -p pass

To check the expected arguments run:

rsconfig.exe /?

Update:

This is actually incorrect, if you look at the expected arguments it states the server name has to include the instance name as well, you can't have quotes and if the instance name contains a $ sign you may need to escape it, see here for more info: https://stackoverflow.com/a/56370766/495455

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文