In Microsoft System Center Configuration Manager 2007, you perform a synchronous query for Configuration Manager 2007 objects by calling the SWbemServices object ExecQuery method and passing a WQL query.

A synchronous query is a query that maintains control over the process of your application for the duration of the query. A synchronous query has the potential of locking up your application for large queries or for queries over a network. Alternatively, you can run an asynchronous query that returns control to the application while the query is run. For more information, see How to Perform an Asynchronous Configuration Manager Query by Using Managed Code

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

To perform a synchronous 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. Using the SWbemServices object that you obtain from step one, use the ExecQuery method to get a SWbemObjectSet collection containing the query results.

  3. Iterate through the SWbemObjectSet collection to access a SWbemObject for each object returned by the query.

Example

The following example performs a synchronous query of all packages in Configuration Manager.

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

Visual Basic Script  Copy Code
Sub QueryPackages(connection)

	On Error Resume next

	Dim packages
	Dim package

	' Run the query.
	Set packages = _
		connection.ExecQuery("Select * From SMS_Package")

	If Err.Number<>0 Then
		Wscript.Echo "Couldn't get Packages"
		Wscript.Quit
	End If
 
	For Each package In packages
		WScript.Echo  package.Name
	Next

	If packages.Count=0 Then
		Wscript.Echo "No packages found"
	End If

End Sub

This example method has the following parameters:

Parameter Type Description

connection

SWbemServices

A valid connection to the SMS Provider.

See Also


Send comments about this topic to Microsoft.