C# wmi 查询异常无效类使用ManagmentObjectSearcher [英] C# wmi query exception invalid class using ManagmentObjectSearcher

查看:41
本文介绍了C# wmi 查询异常无效类使用ManagmentObjectSearcher的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 c# 中使用 System.Management 运行 wmi 查询并不断获取无效类.它用于使用 pcoip 协议的 wmware 虚拟桌面.我可以使用 WMI Explorer,它显示如下.

I am trying to run a wmi query using System.Management in c# and keep getting invalid class. It is for wmware virtual desktops using the pcoip protocol. I can use WMI Explorer and it shows like below.

这里只是一些示例 c# 代码.我知道它没有使用使用"声明我只是想保持简短.我注意到如果我在 WMI 资源管理器中选择顶级命名空间并尝试运行查询它会因相同的无效类错误而失败,然后如果我单击 ROOT\CIMV2 并运行查询它工作正常.我已经检查了范围等中的路径,它似乎是正确的.我也不能使用 Microsoft.Management.Infrastructure.

Here is just some example c# code. I know its not using "using" statements I am just trying to keep it short. I have noticed if I select the top level namespace in WMI Explorer and try to run query it fails with same invalid class error and then if I click on ROOT\CIMV2 and run query it works fine. I have checked path in scope etc and it appears to be correct. I can't use Microsoft.Management.Infrastructure as well.

            var scope = new ManagementScope(ManagementPath.DefaultPath);
            var query = new SelectQuery("SELECT * from Win32_PerfRawData_TeradiciPerf_PCoIPSessionImagingStatistics");
            scope.Connect();
            var searcher = new ManagementObjectSearcher(scope, query);
            var collection = searcher.Get();

注意我可以使用powershell并使用

Note I can use powershell and retrieve using

Get-WmiObject -Class "Win32_PerfRawData_TeradiciPerf_PCoIPSessionImagingStatistics"

更新:奇怪,但我注意到我可以在 WMI 资源管理器中看到,但如果使用 WMI 代码创建器,我看不到.

UPDATE: Strange but I noticed I can see in WMI Explorer but if using WMI Code Creator I do not see.

推荐答案

LMAO... 看到它在 WMI Explorer 中有效但在 WMI Code Creater 中无效,这让我开始思考,尤其是在查看 WMI Explorer 的源代码并意识到它正在做之后代码上和我一样.在任务管理器中查看,发现 WMI Explorer 作为 64 位应用程序运行,而 WMI Code Creator 以 32 位运行.好吧,在 64 位编译后,您知道它的工作原理是什么.我错误地假设所有 WMI 提供程序都有 32 位和 64 位版本,这显然不是这种情况.好消息是我想使用性能计数器而不是 WMI 并且在使用性能计数器而不是使用 WMI 查询编译为 64 之后你知道什么我现在也可以看到性能计数器类别.希望这是我今年最后一个空头时刻.

LMAO... Well seeing it work in WMI Explorer but not in WMI Code Creater got me thinking especially after reviewing source code of WMI explorer and realizing it was doing same thing codewise that I was. Looked in task manager and low and behold WMI Explorer was running as a 64bit application while WMI Code Creator was running in 32bit. Well after compiling in 64 what do you know it works. I wrongly just assumed all WMI providers had a 32bit and 64 bit version which is not the case obviously. Great news is I wanted to use the performance counters instead of WMI and what do you know after compiling as 64 using performance counters instead of using WMI queries I can now see the performance counter categories as well. Hopefully that is my last airhead moment of the year.

这篇关于C# wmi 查询异常无效类使用ManagmentObjectSearcher的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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