In my console application(.NET) i am executing WMI query as follows:
ManagementObjectSearcher query;
ObjectQuery oq;
ManagementObjectCollection objectCollection;
try
{
oq = new ObjectQuery("SELECT TotalVisibleMemorySize, FreePhysicalMemory FROM Win32_OperatingSystem");
query = new ManagementObjectSearcher(oq);
objectCollection = query.Get();
}
catch
{
return null;
}
return objectCollection;
I am doing division on the data collected to use in my application. It is working perfectly for me at the moment.
I am using multiple wmi queries for my application. In order to make a single method to execute all my wmi queries from config I will need to do the division in the select clause of query it self.
I need to execute WMI query like follows:
SELECT ((TotalVisibleMemorySize)/1024) as TotalVisibleMemorySize1, ((FreePhysicalMemory)/1024) as FreePhysicalMemory1 FROM Win32_OperatingSystem
For this query i am getting error Invalid query.
Is there a syntax mistake in this query or is it not possible to do division in the select clause of a WMi query?
Seems WMI doesn’t supports complex queries. Your best bet is to capture wmi results and convert as needed: