Share via


How to Modify Advertisement 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 an existing advertisement, in Microsoft System Center Configuration Manager 2007, by using the SMS_Advertisement Server WMI Class class and class properties.

To modify advertisement properties

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

  2. Get the specific advertisement using an existing advertisement ID.

  3. Replace the existing advertisement property (in this case, advertisement comment).

  4. Save the new advertisement and properties.

Example

The following example method modifies advertisement properties for software distribution.

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

Sub ModifyAdvertisement(connection, existingAdvertisementID, newAdvertisementComment )

    ' Get the specific advertisement instance to modify. 
    Set advertisementToModify = connection.Get("SMS_Advertisement.AdvertisementID='" & existingAdvertisementID & "'")
    
    ' List the existing property values.
    Wscript.Echo " "
    Wscript.Echo "Values before change: "
    Wscript.Echo "--------------------- "
    Wscript.Echo "Advertisement Name: " & advertisementToModify.AdvertisementName
    Wscript.Echo "Comment:            " & advertisementToModify.Comment
    
    ' Set the new property value.
    advertisementToModify.Comment = newAdvertisementComment
    
    ' Save the advertisement.
    advertisementToModify.Put_ 
    
    ' Output the new property values.
    Wscript.Echo " "
    Wscript.Echo "Values after change:  "
    Wscript.Echo "--------------------- "
    Wscript.Echo "Advertisement Name: " & AdvertisementToModify.AdvertisementName
    Wscript.Echo "Comment:            " & AdvertisementToModify.Comment

End Sub
public void ModifySWDAdvertisement(WqlConnectionManager connection, string existingAdvertisementID, string newAdvertisementComment)
{
    try
    {
        // Get the specific advertisement instance to modify. 
        IResultObject advertisementToModify = connection.GetInstance(@"SMS_Advertisement.AdvertisementID='" + existingAdvertisementID + "'");

        // List the existing property values.
        Console.WriteLine();
        Console.WriteLine("Values before change:");
        Console.WriteLine("_____________________");
        Console.WriteLine("Advertisement Name: " + advertisementToModify["AdvertisementName"].StringValue);
        Console.WriteLine("Comment: " + advertisementToModify["Comment"].StringValue);

        // Set the new property value to  be modified.
        advertisementToModify["Comment"].StringValue = newAdvertisementComment;
        
        // Save the advertisement with the new value.
        advertisementToModify.Put();

        // Output the new property values.
        Console.WriteLine();
        Console.WriteLine("Values after change:");
        Console.WriteLine("____________________");
        Console.WriteLine("Advertisement Name: " + advertisementToModify["AdvertisementName"].StringValue);
        Console.WriteLine("Comment: " + newAdvertisementComment);
    }
    catch (SmsException ex)
    {
        Console.WriteLine("Failed to modify advertisement. 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.

existingAdvertisementID

  • Managed: String

  • VBScript: String

The ID of the advertisement to modify.

newAdvertisementComment

  • Managed: String

  • VBScript: String

The new comment for the advertisement.

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 Advertisements
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_Advertisement Server WMI Class