You initiate a software updates scan cycle, in Microsoft System Center Configuration Manager 2007, by creating an instance of the CPAppletMgr Client COM Automation Class, identifying the client action, and running the client action by using the PerformAction method.

To initiate the software updates scan 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, Updates Source Scan Cycle).

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

Example

The following example method shows how to initiate a software updates evaluation cycle by using the CPAppletMgr COM class.

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

Visual Basic Script  Copy Code
Sub InitiateSoftwareUpdatesScanCycle()

	' Set the required variables. 
	actionNameToRun = "Updates Source Scan Cycle"

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

	' Get the available ClientActions object.
	Dim oClientActions
	Set oClientActions = oCPAppletMgr.GetClientActions()

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

	wscript.echo "Ran: " & actionNameToRun

End Sub
C#  Copy Code
public void InitiateSoftwareUpdatesScanCycle()
{
	try
	{
		// Set the required variables. 
		string actionNameToRun = "Updates Source Scan 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


Send comments about this topic to Microsoft.