在 Configuration Manager 中,若要使用受控 SMS 提供者新增內容限定符,請使用 Context 屬性,此屬性是Dictionary保存內容限定符的物件。
一般而言,您會將應用程式名稱新增至 ApplicationName 內容限定符,以及計算機名稱 (MachineName) 和 LocaleID (LocaleID) 。
新增 Configuration Manager 限定符
設定與SMS提供者的連線。 如需詳細資訊,請參閱如何使用Managed程式碼在 Configuration Manager 中聯機到SMS提供者
從步驟 1 取得的 WqlConnectionManager 物件取得 SmsNamedValuesDictionary 物件。
視需要新增內容限定符。
範例
下列 C# 範例會先將一些內容限定符新增至 WQLConnectionManager 物件 Context 字典屬性。 然後,它會在字典對象中顯示內容限定符的清單。
注意事項
WqlConnectionManager 衍生自 ConnectionManagerBase。
在此範例中 LocaleID ,內容限定符會硬式編碼為英文 (美國 ) 。 如果您需要非美國地區設定安裝時,您可以從 SMS_Identification Server WMI ClassLocaleID 屬性取得它。
如需呼叫範例程式代碼的相關信息,請參閱呼叫 Configuration Manager 代碼段。
public void AddContextQualifiers(WqlConnectionManager connection)
{
try
{
connection.Context.Add("ApplicationName", "My application name");
connection.Context.Add("MachineName","Computername");
connection.Context.Add("LocaleID", @"MS\1033");
foreach (KeyValuePair<string, object> namedValue in connection.Context)
{
Console.WriteLine(namedValue.Key);
Console.WriteLine(namedValue.Value);
Console.WriteLine();
}
}
catch (SmsException e)
{
Console.WriteLine("Failed to add context qualifier : " + e.Message);
}
}
範例方法具有下列參數:
| 參數 | Type | 描述 |
|---|---|---|
connection |
- WqlConnectionManager | SMS 提供者的有效連線。 |
正在編譯程式碼
命名空間
系統
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 提供者