查询“Win32_Product”WMI类时出错 - COMException(0x800706BE)

时间:2014-04-02 19:10:00

标签: c# events powershell wmi windows-server-2008

我正在尝试在我们的每台服务器本地上收集所有已安装的SW,并且我正在使用Win32_Product WMI类,但在我们的某些服务器上(使用Win server 2003或2008 R2)我无法查询此类。

这是PowerShell的输出:

C:\Users\e****l> Get-WmiObject -Query "SELECT * FROM Win32_Product"
Get-WmiObject :
At line:1 char:14
+ Get-WmiObject <<<<  -Query "SELECT * FROM Win32_Product"
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], COMException
    + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

我还使用了由WMI Code Creator(由Microsoft提供)

生成的C#代码
        try
        {
            ManagementObjectSearcher searcher =
                new ManagementObjectSearcher("root\\CIMV2",
                "SELECT * FROM Win32_Product");

            foreach (ManagementObject queryObj in searcher.Get())
            {
                Console.WriteLine("-----------------------------------");
                Console.WriteLine("Win32_Product instance");
                Console.WriteLine("-----------------------------------");
                Console.WriteLine("Name: {0}", queryObj["Name"]);
            }
        }
        catch (ManagementException e)
        {
            MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
        }

以下是此输出:

Unhandled Exception: System.Runtime.InteropServices.COMException (0x800706BE)
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   at System.Management.ManagementObjectCollection.ManagementObjectEnumerator.MoveNext()
   at WMISample.MyWMIQuery.Main()

Windows日志显示此事件

enter image description here

我会感谢任何帮助, 感谢

0 个答案:

没有答案