クエリで返された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 遅延プロパティから取得したルール名を表示します。
サンプル コードの呼び出しについては、「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 クエリを実行する方法