다음을 통해 공유


How to Perform an Asynchronous Configuration Manager Query by Using WMI

Applies To: System Center Configuration Manager 2007, System Center Configuration Manager 2007 R2, System Center Configuration Manager 2007 R3, System Center Configuration Manager 2007 SP1, System Center Configuration Manager 2007 SP2

In Microsoft System Center Configuration Manager 2007, you perform an synchronous query for Configuration Manager objects by calling the SWbemServices object ExecQueryAsync method and by implementing a sink method to handle query results.

To handle each returned object, create an objWbemSink.OnObjectReady event subroutine. To be notified when the query is completed, create a objWbemSink.OnCompleted event subroutine.

Note

Lazy properties are not returned in asynchronous queries. For more information, see How to Read Lazy Properties by Using WMI.

To perform an asynchronous query

  1. Set up a connection to the SMS Provider. For more information, see How to Connect to an SMS Provider in Configuration Manager by Using WMI.

  2. Create an OnObjectReady subroutine to handle objects by the query.

  3. Create an OnCompleted subroutine to handle query completion.

  4. Using the SWbemServices object you obtain from step one, use ExecQueryAsync object to query Configuration Manager 2007 objects asynchronously.

Example

The following VBScript code example asynchronously queries for all SMS_Collection objects.

For information about calling the sample code, see Calling Configuration Manager Code Snippets.

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

This example method has the following parameters:

Parameter Type Description

connection

SWbemServices

A valid connection to the SMS Provider.

See Also

Concepts

Configuration Manager Objects Overview
How to Call a Configuration Manager Object Class Method by Using WMI
How to Connect to an SMS Provider in Configuration Manager by Using WMI
How to Create a Configuration Manager Object by Using WMI
How to Delete a Configuration Manager Object by Using WMI
How to Modify a Configuration Manager Object by Using WMI
How to Perform a Synchronous Configuration Manager Query by Using WMI
How to Read a Configuration Manager Object by Using WMI
How to Read Lazy Properties by Using WMI
How to Use Configuration Manager Objects with WMI
Configuration Manager Extended WMI Query Language
Configuration Manager Result Sets
Configuration Manager Special Queries
Configuration Manager Queries

Other Resources

https://go.microsoft.com/fwlink/?LinkId=43950