Compartir a través de


How to Run a Configuration Manager Client Action

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

In Microsoft System Center Configuration Manager 2007, you run a Configuration Manager 2007 client action by calling the PerformAction method on the actions retrieved by CPAppletMgr object GetClientActions method.

To run a Configuration Manager client action

  1. Get the Configuration Manager client Control Panel manager object (CPAppletMgr).

  2. From CPAppletMgr, call GetClientActions to retrieve a collection of Configuration Manager client actions.

  3. Loop through the collection and call PerformAction for each action you want to perform.

Example

The following example method gets the Configuration Manager client actions and performs each one by calling PerformAction.

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

Sub PerformAction

On Error Resume Next

    Dim oCPAppletMgr ' Control Applet manager object
    Dim oClientAction ' Individual client action
    Dim oClientActions ' A collection of client actions

    ' Get the Control Panel applet manager object.
    Set  oCPAppletMgr=CreateObject("CPApplet.CPAppletMgr")
    If err.number <> 0 Then
        Wscript.echo "Couldn't create control panel application manager"
        Exit Sub
    End If

    ' Get a collection of actions.
    Set oClientActions=oCPAppletMgr.GetClientActions
    If err.number<>0 Then
        wscript.echo "Couldn't get the client actions"
        Set oCPAppletMgr=Nothing
        Exit Sub
    End If

    ' Display each client action name and perform it.
    For Each oClientAction In oClientActions
        wscript.echo oClientAction.name
        oClientAction.PerformAction
        wscript.echo
    Next

    Set oClientActions=Nothing
    Set oCPAppletMgr=Nothing

End Sub
public void PerformAction()
{
    try
    {

        CPAppletMgr cpAppletMgr = new CPAppletMgr();

        ClientActions clientActions = cpAppletMgr.GetClientActions();

        foreach (ClientAction action in clientActions)
        {
            Console.WriteLine("Name: " + action.Name);
            action.PerformAction();
            Console.WriteLine();
        }
    }
    catch (COMException e)
    {
        Console.WriteLine("Error performing actions: " + e.Message);
        throw;
    }

}

The example method has no parameters:

Compiling the Code

This C# example requires:

Namespaces

System

System.Collections.Generic

System.Text

System.Runtime.InteropServices

CPAPPLETLib

Assemblies

CPApplet 1.0 Type Library

Robust Programming

For more information about error handling, see About Configuration Manager Errors.

Security

For more information about securing Configuration Manager applications, see About Securing Configuration Manager Applications.

See Also

Concepts

About Configuration Manager Control Panel Configuration
Configuration Manager Client Control Panel Configuration
How to View the Configuration Manager Client Components
How to View the Configuration Manager Client Properties
How to Call Configuration Manager COM Automation Objects