Compartilhar via


How to Initiate a Content Maintenance Cycle on a Branch Distribution Point

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

To initiate a content maintenance cycle on a branch distribution point in Microsoft System Center Configuration Manager 2007, your application can use the CPAppletMgr Client COM Automation Class. This class provides an automated way to perform all the same tasks as the Configuration Manager Management Control Panel program on a client.

To initiate a content maintenance cycle

  1. Create a CPAppletMgr Client COM Automation Class instance.

  2. Get the available client actions.

  3. Enumerate through the client actions until a match is found (in this case, Peer Distribution Point Maintenance Task).

  4. Run the client action by using the IClientAction::PerformAction Method method.

Example

The following example method initiates a content maintenance cycle on a branch distribution point. It uses the hard-coded string, "Peer DP Maintenance Task". A useful modification would be to pass in the actionNameToRun value.

For information about calling the sample code, see How to Call Configuration Manager COM Automation Objects

' Set required variables.
actionNameToRun = "Peer DP Maintenance Task"

' Create a CPAppletMgr instance.
Set controlPanelAppletManager = CreateObject("CPApplet.CPAppletMgr")

' Get the available ClientActions object.
Set availableClientActions = controlPanelAppletManager.GetClientActions()

' Loop through the available client actions. Run matching client action when found.
For Each clientAction In availableClientActions
    If clientAction.Name = actionNameToRun Then
        clientAction.PerformAction  
        
        wscript.echo "Ran: " & clientAction.Name
    End If
Next
public void RunBranchDistributionPointMaintenanceTask()
{
    try
    {
        // Set required variables.
        string actionNameToRun = "Peer DP Maintenance Task";

        // Create CPAppletMgr instance.
        CPAPPLETLib.CPAppletMgr controlPanelAppletManager = new CPAPPLETLib.CPAppletMgr();

        // Loop through the available client actions. Run matching client action when found.
        foreach (CPAPPLETLib.ClientAction possibleClientAction in controlPanelAppletManager.GetClientActions())
        {                    
            if (possibleClientAction.Name == actionNameToRun)
            {
                possibleClientAction.PerformAction();
                Console.WriteLine("Ran: " + possibleClientAction.Name);
            }
        }
    }
    catch (COMException ex)
    {
        Console.WriteLine("Failed to run branch distribution point maintenance task. Error: " + ex.Message);
        throw;
    }
}

The example method has no parameters.

Compiling the Code

The C# example requires:

Namespaces

System

System.Runtime.InteropServices

CPAPPLETLib COM Automation Library

COM Automation

The reference needed for early binding is CPApplet 1.0 Type Library. This creates a type library reference named CPAppletLib. The early binding object name for the Control Panel Manager is CPAppletMgr.

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
Distribution Points
How to Call Configuration Manager COM Automation Objects