tags:

views:

100

answers:

1

My C# .NET 2.0 application performs two queries using the ManagementObjectSearcher class:

_searcher = new ManagementObjectSearcher("root\\WMI", "SELECT * FROM MSWmi_PnPInstanceNames");

_searcher = new ManagementObjectSearcher("root\\WMI", "SELECT * FROM MSSerial_PortName");

I would like to combine them, so that _searcher contains all the results from both queries. However, when I try to do this...

_searcher = new ManagementObjectSearcher("root\\WMI", "SELECT * FROM MSWmi_PnPInstanceNames AND MSSerial_PortName");

...an "Invalid query" exception is thrown. Does anyone have any ideas as to how I can make this work? Thanks.

+1  A: 

Unfortunately, the WMI query language does not support join or union operations, so you have to run these queries separately (since the select from different object stores).

The WMI Query Language (WQL) is a subset of ANSI SQL — with some semantic changes. Not everything you can do in SQL is possible in WQL. You can see the WMI supported query constructs online at MSDN.

LBushkin