若要呼叫 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;
}
}
此範例方法具有下列參數:
| 參數 | Type | 描述 |
|---|---|---|
connection |
- 託管: WqlConnectionManager | 與 SMS 提供者的有效連線。 |
wqlQuery |
- 受管理: IResultObject | WQL 查詢字串。 在此範例中, SELECT * FROM SMS_R_System 是有效的查詢。 |
正在編譯程式碼
命名空間
系統
System.Collections.Generic
System.ComponentModel
Microsoft.ConfigurationManagement.ManagementProvider
Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine
組件
Microsoft.ConfigurationManagement.ManagementProvider
adminui.wqlqueryengine
健全的程式設計
可能引發的 Configuration Manager 例外狀況包括 SmsConnectionException 和 SmsQueryException。 這些可以與 SmsException 一起捕捉。
另請參閱
物件概觀如何使用受控程式碼連線到 Configuration Manager 提供者如何使用 Managed 程式碼建立 Configuration Manager 物件如何使用 Managed 程式碼修改 Configuration Manager 物件如何執行非同步使用 Configuration Manager 使用受控程式碼進行查詢如何使用受控程式碼執行同步 Configuration Manager 查詢如何使用受控程式碼讀取 Configuration Manager 物件