다음을 통해 공유


How to Perform a Synchronous 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 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.

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

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 an Asynchronous 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