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.

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.


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.

Visual Basic Script  Copy Code
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
 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
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



A valid connection to the SMS Provider.

See Also

Send comments about this topic to Microsoft.