How to Modify Program Properties
Applies To: System Center 2012 Configuration Manager, System Center 2012 Configuration Manager SP1, System Center 2012 R2 Configuration Manager
The following example shows how to modify a program, in System Center 2012 R2 Configuration Manager, by using the SMS_Package and SMS_Program classes and properties.
To modify program properties
Set up a connection to the SMS Provider.
Get the program instance using the package ID and program name provided.
Replace the program description property with the one passed into the method.
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). Dim program
Set program = connection.Get("SMS_Program.PackageID='" & existingPackageID & "'" & ",ProgramName='" & existingProgramNameToModify & "'")
' Replace the existing program property (in this case the program description).
program.Description = newProgramDescription
program.Comment = 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;
program["Comment"].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 |
|
A valid connection to the SMS Provider. |
|
existingPackageID |
|
The ID of an existing package with which to associate the program. |
|
existingProgramNameToModify |
|
The name for the program to modify. |
|
newProgramDescription |
|
The description for the new program. |
Compiling the Code
The C# example requires:
Namespaces
System
Microsoft.ConfigurationManagement.ManagementProvider
Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine
Assembly
adminui.wqlqueryengine
microsoft.configurationmanagement.managementprovider
mscorlib
Robust Programming
For more information about error handling, see About Configuration Manager Errors.
See Also
Configuration Manager Software Distribution
Software Distribution Packages
Software Distribution Programs