Reputation: 404
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.
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();
Note I can use powershell and retrieve using
Get-WmiObject -Class "Win32_PerfRawData_TeradiciPerf_PCoIPSessionImagingStatistics"
UPDATE: Strange but I noticed I can see in WMI Explorer but if using WMI Code Creator I do not see.
Upvotes: 0
Views: 1841
Reputation: 404
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.
Upvotes: 1