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.

Visual Basic Script  Copy Code
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
C#  Copy Code
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


Send comments about this topic to Microsoft.