C# 如何解决 WMI 请求的“提供程序加载失败”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/563150/
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-08-04 08:17:57  来源:igfitidea点击:

How can I resolve a "Provider load failure" for WMI requests?

c#.netwmi

提问by Chris Thompson

I'm using WMI to collect system information. It works fine on every system I've tested it on, but I have one or two users that are reporting problems. The debug logs show the WMI code is throwing a "Provider load failure" exception. I haven't been able to replicate the issue.

我正在使用 WMI 来收集系统信息。它在我测试过的每个系统上都运行良好,但我有一两个用户报告了问题。调试日志显示 WMI 代码抛出“提供程序加载失败”异常。我一直无法复制这个问题。

The users have verified that the WMI service is running in Automatic mode.

用户已验证 WMI 服务在自动模式下运行。

Here's the exception:

这是例外:

System.Management.ManagementException: Provider load failure 
   at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode)
   at System.Management.ManagementObjectCollection.ManagementObjectEnumerator.MoveNext()

Any thoughts on how to troubleshoot and resolve this issue?

关于如何排除故障和解决此问题的任何想法?

采纳答案by C. Ross

You might want to confirm all the dlls are properly registered (see http://msdn.microsoft.com/en-us/library/bb961987.aspx).

您可能想要确认所有 dll 都已正确注册(请参阅http://msdn.microsoft.com/en-us/library/bb961987.aspx)。

回答by Richard

WMI registration is all held in WMI (static classes.

WMI 注册都保存在 WMI(静态类。

WMI CIM Studio (part of WMI Tools from MS, IIRC) is useful for exploring these classes (and certainly easier than writing lots of queries).

WMI CIM Studio(MS、IIRC 的 WMI 工具的一部分)对于探索这些类很有用(当然比编写大量查询更容易)。

回答by Precipitous

On operating systems with User Account Control turn off UAC.

在具有用户帐户控制的操作系统上关闭 UAC。

In my case: Ross's answer about did not resolve. I could load some WMI providers (logicaldisk) but not others (IIS). WMI explorer tools (such as PowerGui) would show the provider. This suggested that security policy can prevent loading WMI providers. Once UAC was turned off all WMI providers loaded without error.

就我而言:罗斯的回答没有解决。我可以加载一些 WMI 提供程序(逻辑磁盘),但不能加载其他(IIS)。WMI 资源管理器工具(例如 PowerGui)将显示提供程序。这表明安全策略可以阻止加载 WMI 提供程序。关闭 UAC 后,所有 WMI 提供程序都正确加载。

Of course, you might want to leave UAC on. I'll update this answer if I find the specific policies required.

当然,您可能希望保留 UAC。如果我找到所需的特定政策,我会更新此答案。

回答by Jeremy

So, I know this is old, but I was having the exact problem described above. It was really tough for me to figure out, so I thought I would respond in hopes it helps someone else out.

所以,我知道这很旧,但我遇到了上面描述的确切问题。我真的很难弄清楚,所以我想我会做出回应,希望它能帮助别人。

I was attempting to load the IIS WMI Provider and getting the "Provider Load Failure" error. I could reproduce the problem by running my WMI query using the wbemtest.exe program.

我试图加载 IIS WMI 提供程序并收到“提供程序加载失败”错误。我可以通过使用 wbemtest.exe 程序运行我的 WMI 查询来重现该问题。

I fired up procmon.exe to show what was being loaded (or failing to load in my case) and sure enough, wmiprvse.exe was loading a registry key was saying that inetsrv was located in the C:\windows directory - which did not exist on my machine (C:\windows had been replaced by c:\winnt)

我启动了 procmon.exe 以显示正在加载的内容(或在我的情况下无法加载),果然,wmiprvse.exe 正在加载一个注册表项,说 inetsrv 位于 C:\windows 目录中 - 这并没有存在于我的机器上(C:\windows 已被 c:\winnt 替换)

Updating the key resolved my issue, but the bigger point here is that I had one hell of a time trying to figure out why I was getting this error, and running procmon while executing my WMI query pointed me right to the problem. Hopefully it will for you too.

更新密钥解决了我的问题,但这里更重要的一点是,我花了一段时间试图弄清楚为什么会出现此错误,并且在执行 WMI 查询时运行 procmon 直接指出了问题所在。希望它也适合你。

回答by Joshua Drake

One way to possibly track down the root cause of the issue is to use WBEMTesta tool that the MS Scripting Guys say is one of the easiest ways

可能追查问题根本原因的一种方法是使用WBEMTest,MS 脚本专家认为该工具是最简单的方法之一

"To find the provider of a WMI class..."

“要查找 WMI 类的提供者...”

The Scripting Guys: Use PowerShell to Troubleshoot “Provider Load Failure”

脚本专家:使用 PowerShell 对“提供程序加载失败”进行故障排除

The high level steps specific to the Win32_NetworkAdapter are described in this Win32_network adapter "provider load failure"post by Mark Wolzak at infoSupport.

特定于 Win32_NetworkAdapter 的高级步骤在此Win32_network 适配器“提供程序加载失败”中由 Mark Wolzak 在 infoSupport 中描述。

  • Click start >> run >> wbemtest
  • click 'Connect…' to connect to a namespace
  • execute the query 'Select * From MSFT_WmiSelfEvent'
  • scroll down to the bottom and trace the following WMI events
  • Look at the details of any Msft_WmiProvider_InitializationOperationFailureEvent or Msft_WmiProvider_LoadOperationFailureEvent for the dll that is causing the issue
  • 单击开始 >> 运行 >> wbemtest
  • 单击“连接...”以连接到命名空间
  • 执行查询“Select * From MSFT_WmiSelfEvent”
  • 向下滚动到底部并跟踪以下 WMI 事件
  • 查看导致问题的 dll 的任何 Msft_WmiProvider_InitializationOperationFailureEvent 或 Msft_WmiProvider_LoadOperationFailureEvent 的详细信息

Thanks to the WMI–Provider Load Failurepost at Richard Siddaway's Blog for pointing me to this tool and specific methodology.

感谢Richard Siddaway 博客上的WMI–Provider Load Failure帖子,让我了解此工具和特定方法。