C# .NET ManagementObjectSearcher 查询
我的 C# .NET 2.0 应用程序使用 ManagementObjectSearcher
类执行两个查询:
_searcher = new ManagementObjectSearcher("root\\WMI", "SELECT * FROM MSWmi_PnPInstanceNames");
_searcher = new ManagementObjectSearcher("root\\WMI", "SELECT * FROM MSSerial_PortName");
我想将它们组合起来,以便 _searcher
包含两个查询的所有结果。但是,当我尝试这样做时...
_searcher = new ManagementObjectSearcher("root\\WMI", "SELECT * FROM MSWmi_PnPInstanceNames AND MSSerial_PortName");
...抛出“无效查询”异常。有人对我如何使这项工作有任何想法吗?谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
遗憾的是,WMI 查询语言不支持
join
或union
操作,因此您必须单独运行这些查询(因为从不同的对象中选择)商店)。WMI 查询语言 (WQL) 是 ANSI SQL 的子集 — 具有一些语义更改。并非所有在 SQL 中能做的事情都可以在 WQL 中实现。您可以查看 WMI 支持的查询构造 在线访问 MSDN。
Unfortunately, the WMI query language does not support
join
orunion
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.
我能够使用多个表运行查询,如下所示
希望这有帮助
I am able to run query with multiple tables as shown below
Hope this helps