You install software updates, in Microsoft System Center Configuration Manager 2007, by creating an instance of the CCMUpdatesDeployment COM class and using the InstallUpdates method.

To install software updates

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

  2. Create an array of update IDs (updatesList in this example, where updatesList is all of the enumerated updates) to pass to the InstallUpdates method.

  3. Install the updates by using the InstallUpdates method.


The following example method shows how to install software updates by creating an instance of the CCMUpdatesDeployment COM class and using the InstallUpdates method.

This example installs all software updates that are available in the client UI, both optional and mandatory.

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

Visual Basic Script  Copy Code
Sub InstallAllUpdates()

	' Initialize the variables.
	dim updatesDeployment
	dim progress
	dim updateCount
	dim update
	dim updatesList

	' Create the UpdatesDeployment instance.
	set updatesDeployment = CreateObject ("UDA.CCMUpdatesDeployment")

	' Get the current updates.
	Set updatesColl = updatesDeployment.EnumerateUpdates( 2, 0, progress )

	' Get a count of the available updates.
	updateCount = updatesColl.GetCount()

	' Before installing, determine whether another job is already in progress.
	if progress = 0 then 

		if updateCount > 0 then
			' Create array to hold update IDs.
			Redim updatesList(updateCount-1)

			' Get the ID for each update.
			for nIndex = 0 To updateCount-1
				Set update = updatesColl.GetUpdate(nIndex)
				updatesList(nIndex) = update.GetId()

			' Download and install the update and check the location before initiating the download.
			updatesDeployment.InstallUpdates updatesList, 0, 1

			WScript.echo "Successfully started installation of the updates."

			WScript.echo "No updates need to be installed."	 
		end if

			WScript.echo "Another update installation is in progress."
	end if 

End Sub
C#  Copy Code
public void InstallSoftwareUpdates()
		// Create the UpdatesDeployment instance.
		UPDATESDEPLOYMENTLib.CCMUpdatesDeploymentClass newCCMUpdatesDeployment = new UPDATESDEPLOYMENTLib.CCMUpdatesDeploymentClass();

	 // Get the current updates.
	 object progress = null;
	 UPDATESDEPLOYMENTLib.ICCMUpdatesCollection updatesCollection = newCCMUpdatesDeployment.EnumerateUpdates(2, true, ref progress);
	 // Get a count of the available updates.
		int updateCount = updatesCollection.GetCount();
		Console.WriteLine("Updates available: " + updatesCollection.GetCount());

	 // Determine whether another installation is already in progress.
	 if (((int)progress == 0))
		 // Determine whether there are any updates to install.
		 if (updateCount > 0)
			 // Create an array to hold the update IDs.
			 string[] updatesList = new string[(updateCount)];
			 // Get the ID for each update.
			 for (int arrayIndex = 0; arrayIndex < updateCount; arrayIndex++)
				 UPDATESDEPLOYMENTLib.ICCMTargetedUpdate update = updatesCollection.GetUpdate(arrayIndex);
				 updatesList[arrayIndex] = update.GetID();

			 // Download and install the update and check the location before initiating the download.
			 newCCMUpdatesDeployment.InstallUpdates(updatesList, 0, 1);

			 Console.WriteLine("Successfully started installation of the updates.");
			 Console.WriteLine("No updates need to be installed.");
		 Console.WriteLine("Another update installation is in progress.");
	 // Output success message.
	 Console.WriteLine("Ran InstallUpdates.");

	catch (COMException ex)
		Console.WriteLine("Failed to run InstallUpdates method. Error: " + ex.Message);

Compiling the Code

This C# example requires:





COM Automation

The reference that is needed for early binding is UpdatesDeploymentAgent 1.0 Type Library. This creates a type library reference named UPDATESDEPLOYMENTLib. The early binding object name for the Control Panel Manager is CCMUpdatesDeploymentClass.

Robust Programming

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


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

See Also

Send comments about this topic to Microsoft.