How to Initiate a Software Metering Usage Report Cycle

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

You initiate a software metering usage report cycle, in Microsoft System Center Configuration Manager 2007, by creating an instance of the CPAppletMgr Client COM Automation Class and running the Software Metering Usage Report Cycle action by using the PerformAction method.

To initiate a software metering usage report cycle

  1. Create a CPAppletMgr instance by using the CPAppletMgr COM class.

  2. Get the available client actions.

  3. Enumerate through the client actions until a match is found (in this case, Software Metering Usage Report Cycle).

  4. Run the client action by using the PerformAction method.

Example

The following example method shows how to initiate a software metering report usage cycle on the client by using the CPAppletMgr COM class.

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

Sub SoftwareMeteringUsageReportCycle()

    ' Set required variables.
    actionNameToRun = "Software Metering Usage Report Cycle"

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

    ' Get the available client actions.
    Dim clientActions
    Set clientActions = CPAppletMgr.GetClientActions()

    ' Loop through the available client actions. Run matching client action when found.
    Dim clientAction
    For Each clientAction In clientActions
        If clientAction.Name = actionNameToRun Then
            clientAction.PerformAction  
        End If
    Next

    ' Output success message.
    wscript.echo "Ran: " & actionNameToRun
    
End Sub
public void InitiateSoftwareMeteringUsageReportCycle()
{
    try
    {
        // Set the required variables.
        string actionNameToRun = "Software Metering Usage Report Cycle";

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

        // Loop through the available client actions. Run the matching client action when it is 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 action. Error: " + ex.Message);
        throw;
    }
}

Compiling the Code

This C# example requires:

Namespaces

System

System.Runtime.InteropServices

CPAPPLETLib COM Automation Library

COM Automation

The reference that is 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

System Center Configuration Manager Software Development Kit
Configuration Manager Software Metering
CPAppletMgr Client COM Automation Class