Share via


How to Configure Package Properties

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

The following example shows how to configure the properties of an existing package, in Microsoft System Center Configuration Manager 2007, by using the SMS_Package Server WMI Class class.

To configure an existing package

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

  2. Load the existing package object by using SMS_Package Server WMI Class class.

  3. Populate any package properties (this example uses package description).

  4. Save the package and the new package properties.

Example

The following example method configures package properties for software distribution.

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

Sub ConfigurePackageProperties(connection, existingPackageID, newPackageDescription)
    
    ' Get the specific package object. 
    Set packageToConfigure = connection.Get("SMS_Package.PackageID='" & existingPackageID & "'")
    
    ' Replace the existing package property (in this case the package description).
    packageToConfigure.Description = newPackageDescription
        
    ' Save the package with the modified properties.
    packageToConfigure.Put_
    
    ' Output package ID and package name.
    wscript.echo "Configured Package "  
    wscript.echo "Package ID:        "  & packageToConfigure.PackageID
    wscript.echo "Package Name:      "  & packageToConfigure.Name

End Sub
public void ConfigurePackageProperties(WqlConnectionManager connection, string existingPackageID, string newPackageDescription)
{
    try
    {
        // Get specific package instance to modify.
        IResultObject packageToConfigure = connection.GetInstance(@"SMS_Package.PackageID='" + existingPackageID + "'");

        // Replace the existing package property with the new value (in this case the package description).
        packageToConfigure["Description"].StringValue = newPackageDescription;

        // Save package and modified package properties.
        packageToConfigure.Put();

        // Output package ID and package name.
        Console.WriteLine("Configured Package ");
        Console.WriteLine("Package ID:        " + packageToConfigure["PackageID"].StringValue);
        Console.WriteLine("Package Name:      " + packageToConfigure["Name"].StringValue);
    }

    catch (SmsException ex)
    {
        Console.WriteLine("Failed to configure package. Error: " + ex.Message);
        throw;
    }
}

The example method has the following parameters:

Parameter Type Description

connection

swbemServices

  • Managed: WqlConnectionManager

  • VBScript: SWbemServices

A valid connection to the SMS Provider.

existingPackageID

  • Managed: String

  • VBScript: String

The ID of the existing package.

newPackageDescription

  • Managed: String

  • VBScript: String

The description for the new package.

Compiling the Code

The C# example requires:

Namespaces

System

System.Collections.Generic

System.ComponentModel

Microsoft.ConfigurationManagement.ManagementProvider

Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

Assembly

adminui.wqlqueryengine

microsoft.configurationmanagement.managementprovider

Robust Programming

For more information about error handling, see About Configuration Manager Errors.

Security

For more information about securing Configuration Manager applications, see Securing Configuration Manager Applications.

See Also

Concepts

Configuration Manager Software Distribution
Software Distribution Packages
About the Configuration Manager Site Control File
How to Read and Write to the Configuration Manager Site Control File by Using Managed Code
How to Read and Write to the Configuration Manager Site Control File by Using WMI
SMS_SCI_Component Server WMI Class
SMS_Package Server WMI Class