To modify a Microsoft System Center Configuration Manager 2007 object instance by using the managed SMS Provider, use the object's Microsoft.ConfigurationManagement.ManagementProvider.IResultObject interface to make modifications. You then call the IResultObject.Put method to submit the changes.

Note
The IResultObject interface for an object can be obtained through the WqlConnectionManager.GetInstance method or through other queries. For an example that uses asynchronous queries, see How to Perform an Asynchronous Configuration Manager Query by Using Managed Code.

To modify a Configuration Manager object

  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 Managed Code.

  2. Using the WqlConnectionManager object you obtain in step one, call GetInstance to get an IResultObject for the required object.

  3. Make changes to object using the IResultObject.

  4. Commit the changes to the SMS provider with the IResultObject object Put method.

Example

The following example function updates a package's description from a supplied package identifier and description.

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

  Copy Code
public void ModifyPackageDescription(WqlConnectionManager connection, string packageID, string description)
{
	try
	{
		IResultObject package = connection.GetInstance(@"SMS_Package.PackageID='" + packageID + "'");
		Console.WriteLine("Package Name: " + package["Name"].StringValue);
		Console.WriteLine("Current Description: " + package["Description"].StringValue);

		package["Description"].StringValue = description;

		package.Put();

		Console.WriteLine("New description: " + package["Description"].StringValue);
}
	catch (SmsException ex)
	{
		Console.WriteLine("Failed to get package. Error: " + ex.Message);
		throw;
}
}

This example method has the following parameters:

Parameter Type Description

connection

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

The Configuration Manager exceptions that can be raised are Microsoft.ConfigurationManagement.ManagementProvider.SmsConnectionException and These can be caught together with

See Also


Send comments about this topic to Microsoft.