次の方法で共有


How to Modify a Configuration Manager Object 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 modify a Microsoft System Center Configuration Manager 2007 object instance by using the managed SMS Provider, use the object's 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.

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 SmsConnectionException and These can be caught together with

See Also

Concepts

About Configuration Manager Objects
Configuration Manager Lazy Properties
How to Call a Configuration Manager Object Class Method by Using Managed Code
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 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 Read Lazy Properties by Using Managed Code
How to Use Configuration Manager Objects with Managed Code