次の方法で共有


WMI を使用して非同期Configuration Manager クエリを実行する方法

Configuration Managerでは、SWbemServices オブジェクト ExecQueryAsync メソッドを呼び出し、シンク メソッドを実装してクエリ結果を処理することで、Configuration Manager オブジェクトに対して同期クエリを実行します。

返された各オブジェクトを処理するには、 objWbemSink.OnObjectReady イベント サブルーチンを作成します。 クエリが完了したときに通知されるようにするには、 objWbemSink.OnCompleted イベント サブルーチンを作成します。

注:

非同期クエリでは、遅延プロパティは返されません。 詳細については、「WMI を 使用して遅延プロパティを読み取る方法」を参照してください。

非同期クエリを実行するには

  1. SMS プロバイダーへの接続を設定します。 詳細については、「WMI を使用してConfiguration Managerで SMS プロバイダーに接続する方法」を参照してください。

  2. クエリによってオブジェクトを処理する OnObjectReady サブルーチンを作成します。

  3. クエリの完了を処理する OnCompleted サブルーチンを作成します。

  4. 手順 1 から取得した SWbemServices オブジェクトを使用して、ExecQueryAsync オブジェクトを使用して、Configuration Manager オブジェクトに対して非同期的にクエリを実行します。

次の VBScript コード例では、すべての SMS_Collection オブジェクトに対して非同期的にクエリを実行します。

サンプル コードの呼び出しについては、「Configuration Manager コード スニペットの呼び出し」を参照してください。

Dim bdone  
Sub QueryCollection(connection)  

    Dim sink  
    bdone = False  

    Set sink = WScript.CreateObject("wbemscripting.swbemsink","sink_")  

    ' Query for all collections.  
    connection.ExecQueryAsync sink, "select * from SMS_Collection"  

    ' Wait until all instances are returned.  
    While Not bdone      
        wscript.sleep 1000  
    Wend  
 End Sub     

' The sink subroutine to handle the OnObjectReady   
' event. This is called as each object returns.  
Sub sink_OnObjectReady(collection, octx)  
    WScript.Echo "CollectionID: " + collection.CollectionID  
    WScript.Echo "Name: " + collection.Name  
    Wscript.Echo  
End Sub  

' The sink subroutine to handle the OnCompleted event.  
' This is called when all the objects are returned.   
' The oErr parameter obtains an SWbemLastError object,  
' if available from the provider.  
Sub sink_OnCompleted(HResult, oErr, oCtx)  
    WScript.Echo "All collections returned"  
    bdone = true  
End Sub  

この例のメソッドには、次のパラメーターがあります。

パラメーター 説明
connection SWbemServices SMS プロバイダーへの有効な接続。

関連項目

Windows Management Instrumentation
オブジェクトの概要WMI を使用してConfiguration Manager オブジェクト クラス メソッドを呼び出す方法
WMI を使用してConfiguration Managerで SMS プロバイダーに接続する方法
WMI を使用してConfiguration Manager オブジェクトを作成する方法
WMI を使用してConfiguration Manager オブジェクトを削除する方法
WMI を使用してConfiguration Manager オブジェクトを変更する方法
WMI を使用して同期Configuration Manager クエリを実行する方法
WMI を使用してConfiguration Manager オブジェクトを読み取る方法
WMI を使用して遅延プロパティを読み取る方法
拡張 WMI クエリ言語のConfiguration Manager
結果セットのConfiguration Manager
特殊なクエリをConfiguration Managerする
クエリについて