Compartir a través de


How to Modify Program 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 modify a program, in Microsoft System Center Configuration Manager 2007, by using the SMS_Package Server WMI Class and SMS_Program Server WMI Class classes and properties.

To modify program properties

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

  2. Get the program instance using the package ID and program name provided.

  3. Replace the program description property with the one passed into the method.

  4. Save the program object and properties.

Example

The following example method modifies program properties for software distribution.

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

Sub ModifyProgram(connection, existingpackageID, existingProgramNameToModify, newProgramDescription)  
    
     ' Load the specific program to change (programname is a key value and must be unique).
     Set program = connection.Get("SMS_Program.PackageID='" & existingPackageID & "'" & ",ProgramName='" & existingProgramNameToModify & "'")
        
     ' Replace the existing program property (in this case the program description).
     program.Description = newProgramDescription
     
     ' Save the program with the modified properties.
     program.Put_

     ' Output program name.
     wscript.echo "Modified program: "  & program.ProgramName            
    
End Sub
public void ModifyProgram(WqlConnectionManager connection, string existingPackageID, string existingProgramNameToModify, string newProgramDescription)
{

    try
    {
        
        // Load the specific program to change (programname is a key value and must be unique).
        IResultObject program = connection.GetInstance(@"SMS_Program.PackageID='" + existingPackageID + "',ProgramName='" + existingProgramNameToModify + "'");
        
        // Replace the existing program property (in this case the program description).
        program["Description"].StringValue = newProgramDescription;

        // Save the program with the modified properties.
        program.Put();

        // Output program name.
        Console.WriteLine("Modified program: " + program["ProgramName"].StringValue);
        
    }
    catch (SmsException ex)
    {
        Console.WriteLine("Failed to modify the program. 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 an existing package with which to associate the program.

existingProgramNameToModify

  • Managed: String

  • VBScript: String

The name for the program to modify.

newProgramDescription

  • Managed: String

  • VBScript: String

The description for the new program.

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
Software Distribution Programs
How to Use Configuration Manager Objects with WMI
How to Use Configuration Manager Objects with Managed Code
How to Connect to an SMS Provider in Configuration Manager by Using Managed Code
How to Connect to an SMS Provider in Configuration Manager by Using WMI
SMS_Package Server WMI Class
SMS_Program Server WMI Class