To synchronously query the System Center 2012 Configuration Manager client Windows Management Instrumentation (WMI), you use a ManagementObjectSearcher object.

To read a lazy property from a System Center 2012 Configuration Manager object that is returned in a query, you get the object instance, which in turn retrieves any lazy object properties from the SMS Provider.

To perform a synchronous query

  1. Set up a connection to the System Center 2012 Configuration Manager client WMI namespace. For more information, see How to Connect to the Configuration Manager Client WMI Namespace by Using System.Management.

  2. Create a ManagementObjectSearcher collection, and specify a WQL query.

  3. Iterate through the ManagementObjectSearcher collection to view the ManagementObject for each WMI object that is returned by the query.

Example

The following C# code example queries for the single SMS_Client object that is on a System Center 2012 Configuration Manager client.

For information about calling the sample code, see How to Call a WMI Class Method by Using System.Management.

C#  Copy Code
public void QueryObjects(ManagementScope scope)
{
	try
	{
		ManagementObjectSearcher s = new ManagementObjectSearcher
			((scope), new WqlObjectQuery("SELECT * FROM sms_client"));

		foreach (ManagementObject o in s.Get())
		{
			// There is only one instance of SMS_Client, so this should enumerate only once.
			Console.WriteLine("Client version: " + o["ClientVersion"].ToString());
	}
}
	catch (System.Management.ManagementException e)
	{
		Console.WriteLine("Failed to make query: ", e.Message);
		throw;
}
}

This example method has the following parameters:

Parameter Type Description

scope

ManagementScope

Represents a scope (namespace) for management operations.

Compiling the Code

Namespaces

System.

System.Management.

Assembly

System.Management.

Robust Programming

The exception that can be raised is System.Management.ManagementException.

See Also