So ändern Sie Programmeigenschaften

Das folgende Beispiel zeigt, wie ein Programm im Configuration Manager mithilfe der SMS_PackageSMS_Program und-Klassen und Eigenschaften geändert werden kann.

So ändern Sie Programmeigenschaften

  1. Richten Sie eine Verbindung mit dem SMS-Anbieter ein.

  2. Rufen Sie die Programm-instance mithilfe der Paket-ID und des angegebenen Programmnamens ab.

  3. Ersetzen Sie die Programmbeschreibungseigenschaft durch die an die Methode übergebene.

  4. Speichern Sie das Programmobjekt und die Eigenschaften.

Beispiel

Die folgende Beispielmethode ändert Programmeigenschaften für die Softwareverteilung.

Informationen zum Aufrufen des Beispielcodes finden Sie unter Aufrufen von Configuration Manager-Codeausschnitten.


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;
    }
}

Die Beispielmethode hat die folgenden Parameter:

Parameter Typ Beschreibung
connection

swbemServices
- Verwaltet: WqlConnectionManager
- VBScript: SWbemDienste
Eine gültige Verbindung mit dem SMS-Anbieter.
existingPackageID - Verwaltet: String
- VBScript: String
Die ID eines vorhandenen Pakets, dem das Programm zugeordnet werden soll.
existingProgramNameToModify - Verwaltet: String
- VBScript: String
Der Name für das zu ändernde Programm.
newProgramDescription - Verwaltet: String
- VBScript: String
Die Beschreibung für das neue Programm.

Kompilieren des Codes

Das C#-Beispiel erfordert:

Namespaces

System

Microsoft.ConfigurationManagement.ManagementProvider

Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

Assembly

adminui.wqlqueryengine

Microsoft.ConfigurationManagement.ManagementProvider

MSCorlib

Robuste Programmierung

Weitere Informationen zur Fehlerbehandlung finden Sie unter Informationen zu Configuration Manager-Fehlern.

Siehe auch

Übersicht über die Softwareverteilung