To perform a synchronous query by using the managed SMS Provider, you use WqlConnectionManager.QueryProcessor.ExecuteQuery method.

The ExecuteQuery method takes a WQL query string and optional context information for the call. An Microsoft.ConfigurationManagement.ManagementProvider.IResultObject is returned containing the objects found in the query.

To perform a synchronous query

  1. Set up a connection to the SMS Provider. For more information, see About the SMS Provider in Configuration Manager.

  2. Using the WqlConnectionManager object you obtain in step one, call the QueryProcessor object ExecuteQuery method to query SMS Provider and get an IResultObject containing a collection of query results.

Example

The following code example shows how to make a synchronous query for the available packages by using ExecuteQuery.

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

  Copy Code
public void QueryPackages(WqlConnectionManager connection)
{
	try
	{
		IResultObject query = connection.QueryProcessor.ExecuteQuery("Select * from SMS_Package");
		foreach (IResultObject o in query)
		{
			Console.WriteLine(o["Name"].StringValue);
			o.Dispose();
	}
}
	catch (SmsException ex)
	{
		Console.WriteLine("Failed to query packages: " + ex.Message);
		throw;
}
}

This example method has the following parameters:

Parameter Type Description

connection

Managed: WqlConnectionManager

A valid connection to the SMS Provider.

Compiling the Code

Namespaces

System

System.Collections.Generic

System.ComponentModel

Microsoft.ConfigurationManagement.ManagementProvider

Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

Assembly

microsoft.configurationmanagement.managementprovider

adminui.wqlqueryengine

Robust Programming

See Also


Send comments about this topic to Microsoft.