クエリーで返された Configuration Manager オブジェクトから遅延プロパティーを読み取るには、オブジェクト・インスタンスを取得し、SMS プロバイダーから遅延オブジェクト・プロパティーを取得します。
注:
WMI オブジェクトへの完全なパスがわかっている場合、 GetInstance メソッドを呼び出すと、WMI オブジェクトが遅延プロパティとともに返されます。 詳細については、「マネージド コードを使用して Configuration Manager オブジェクトを読み取る方法」を参照してください。
詳細については、「Configuration Manager の遅延プロパティ」を参照してください。
遅延プロパティの読み取り
SMS プロバイダーへの接続をセットアップします。 詳細については、「マネージド コードを使用して Configuration Manager で SMS プロバイダーに接続する方法」を参照してください。
QueryProcessor オブジェクトを使用して、Configuration Manager オブジェクトにクエリを実行します。
クエリ結果を反復処理する。
手順 1 で取得した WqlConnectionManager を使用して、 GetInstance を呼び出して、遅延プロパティを取得するクエリ対象オブジェクトごとに IResultObject オブジェクトを取得します。
例
次の C# コード例では、すべての SMS_Collection オブジェクトに対してクエリを実行し、その CollectionRules lazy プロパティから取得したルール名を表示します。
サンプル コードの呼び出しの詳細については、「Configuration Manager コード スニペットの呼び出し」を参照してください。
public void ReadLazyProperty(WqlConnectionManager connection)
{
try
{
// Query all collections.
IResultObject collections = connection.QueryProcessor.ExecuteQuery("Select * from SMS_Collection");
foreach (IResultObject collection in collections)
{
// Get the collection object and lazy properties.
collection.Get();
Console.WriteLine(collection["Name"].StringValue);
// Get the rules.
List<IResultObject> rules = collection.GetArrayItems("CollectionRules");
if (rules.Count == 0)
{
Console.WriteLine("No rules");
Console.WriteLine();
continue;
}
foreach (IResultObject rule in rules)
{
// Display rule names.
Console.WriteLine("Rule name: " + rule["RuleName"].StringValue);
}
Console.WriteLine();
}
}
catch (SmsQueryException ex)
{
Console.WriteLine("Failed to get collection. Error: " + 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 クエリを実行する方法