若要调用 SMS 提供程序类方法,请在 Configuration Manager 中使用 ExecuteMethod 方法。 使用方法的参数填充 Dictionary 对象,返回值是包含方法调用结果的 IResultObject 对象。
注意
若要对对象实例调用方法,请在 IResultObject 对象实例上使用 ExecuteMethod 方法。
调用 Configuration Manager 对象类方法
- 设置与 SMS 提供程序的连接。 有关详细信息,请参阅 SMS 提供程序基础知识。 
- 将输入参数创建为 Dictionary 对象。 
- 使用 WqlConnectionManager 对象实例,调用 ExecuteMethod 并指定类名称和输入参数。 
- 从返回的 IResultObject 对象中的 ReturnValue 属性检索方法返回值。 
示例
以下示例通过调用 SMS_CollectionRuleQuery 类 ValidateQuery 类方法来验证集合规则查询。
有关调用示例代码的信息,请参阅调用Configuration Manager代码片段。
public void ValidateQueryRule(WqlConnectionManager connection, string wqlQuery)
{
    try
    {
        Dictionary<string,object> validateQueryParameters = new Dictionary<string,object>();
        // Add the sql query as the WQLQuery parameter.
        validateQueryParameters.Add("WQLQuery",wqlQuery);
        // Call the method
        IResultObject result=connection.ExecuteMethod("SMS_CollectionRuleQuery", "ValidateQuery", validateQueryParameters);
        if (result["ReturnValue"].BooleanValue == true)
        {
            Console.WriteLine (wqlQuery + " is a valid query");
        }
        else
        {
            Console.WriteLine (wqlQuery + " is not a valid query");
        }
     }
     catch (SmsException ex)
     {
           Console.WriteLine("Failed to validate query rule: ",ex.Message);
           throw;
     }
}
此示例方法具有以下参数:
| 参数 | 类型 | 说明 | 
|---|---|---|
| connection | - 托管: WqlConnectionManager | 与 SMS 提供程序的有效连接。 | 
| wqlQuery | - 托管: IResultObject | WQL 查询字符串。 对于此示例, SELECT * FROM SMS_R_System是有效的查询。 | 
编译代码
命名空间
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对象