若要使用托管 SMS 提供程序执行同步查询,请使用 WqlConnectionManager.QueryProcessor.ExecuteQuery 方法。
ExecuteQuery 方法接受 WQL 查询字符串和调用的可选上下文信息。 返回 一个 IResultObject ,其中包含在查询中找到的对象。
执行同步查询
设置与 SMS 提供程序的连接。 有关详细信息,请参阅 SMS 提供程序基础知识。
使用在步骤 1 中获取的 WqlConnectionManager 对象,调用 QueryProcessor 对象 ExecuteQuery 方法查询 SMS 提供程序,并获取包含查询结果集合的 IResultObject 。
示例
下面的代码示例演示如何使用 ExecuteQuery 对可用包进行同步查询。
有关调用示例代码的信息,请参阅调用Configuration Manager代码片段。
public void QueryPackages(WqlConnectionManager connection)
{
try
{
IResultObject query = connection.QueryProcessor.ExecuteQuery("Select * from SMS_Package");
foreach (IResultObject o in query)
{
Console.WriteLine(o["Name"].StringValue);
o.Dispose();
}
}
catch (SmsException ex)
{
Console.WriteLine("Failed to query packages: " + ex.Message);
throw;
}
}
此示例方法具有以下参数:
参数 | 类型 | 说明 |
---|---|---|
connection |
管理: WqlConnectionManager |
与 SMS 提供程序的有效连接。 |
编译代码
命名空间
System
System.Collections.Generic
System.ComponentModel
Microsoft.ConfigurationManagement.ManagementProvider
Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine
Assembly
microsoft.configurationmanagement.managementprovider
adminui.wqlqueryengine
可靠编程
可以引发Configuration Manager异常是 SmsConnectionException 和 SmsQueryException。 这些可与 SmsException 一起捕获。
另请参阅
对象概述Configuration Manager延迟属性如何使用托管代码调用Configuration Manager对象类方法如何使用托管代码连接到Configuration Manager提供程序如何创建使用托管代码Configuration Manager对象如何使用托管代码修改Configuration Manager对象如何使用托管代码执行异步Configuration Manager查询如何读取Configuration Manager使用托管代码对象 如何使用托管代码读取延迟属性Configuration Manager扩展的 WMI 查询语言Configuration Manager结果集Configuration Manager有关查询的特殊查询