To call a SMS Provider class method, in System Center 2012 Configuration Manager, you use the ExecuteMethod method. You populate a Dictionary object with the method's parameters, and the return value is an IResultObject object that contains the result of the method call.

Note
To call a method on an object instance, use the ExecuteMethod method on the IResultObject object instance.

To call a Configuration Manager object class method

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

  2. Create the input parameters as a Dictionary object.

  3. Using the WqlConnectionManager object instance, call ExecuteMethod and specify the class name and input parameters.

  4. Retrieve the method return value from the ReturnValue property in the returned IResultObject object.

Example

The following example validates a collection rule query by calling the SMS_CollectionRuleQuery class ValidateQuery class method.

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

  Copy Code
public void ValidateQueryRule(WqlConnectionManager connection, string wqlQuery)
{
	try
	{
		Dictionary<string,object> validateQueryParameters = new Dictionary<string,object>();

		// Add the sql query as the WQLQuery parameter.
		validateQueryParameters.Add("WQLQuery",wqlQuery);

		// Call the method
		IResultObject result=connection.ExecuteMethod("SMS_CollectionRuleQuery", "ValidateQuery", validateQueryParameters);
					
		if (result["ReturnValue"].BooleanValue == true)
		{
			Console.WriteLine (wqlQuery + " is a valid query");
	}
		else
		{
			Console.WriteLine (wqlQuery + " is not a valid query");
	}
	 }
	 catch (SmsException ex)
	 {
		 Console.WriteLine("Failed to validate query rule: ",ex.Message);
		 throw;
	 }
}
 

This example method has the following parameters:

Parameter Type Description

connection

  • Managed: WqlConnectionManager

A valid connection to the SMS Provider.

wqlQuery

  • Managed: IResultObject

A WQL query string. For this example, SELECT * FROM SMS_R_System is a valid query.

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

The Configuration Manager exceptions that can be raised are SmsConnectionException and SmsQueryException. These can be caught together with SmsException.

See Also