How to Call a Configuration Manager Object Class Method by Using Managed Code

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

To call a SMS Provider class method, in Configuration Manager 2007, 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.

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

Concepts

About Configuration Manager Objects
How to Connect to an SMS Provider in Configuration Manager by Using Managed Code
How to Create a Configuration Manager Object by Using Managed Code
How to Modify a Configuration Manager Object by Using Managed Code
How to Perform an Asynchronous Configuration Manager Query by Using Managed Code
How to Perform a Synchronous Configuration Manager Query by Using Managed Code
How to Read a Configuration Manager Object by Using Managed Code
How to Use Configuration Manager Objects with Managed Code