How to Install Software Updates

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 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.

Example

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

Note

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

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()
            next

            ' 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."

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

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

End Sub
public void InstallSoftwareUpdates()
{
    try
    {
                     
        // 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.");
           }
           else
           {
               Console.WriteLine("No updates need to be installed.");
           }
       }
       else
       {
           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);
        throw;
    }
}

Compiling the Code

This C# example requires:

Namespaces

System

System.Runtime.InteropServices

UPDATESDEPLOYMENTLib COM Automation Library

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.

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 Updates
About Software Updates Client
CPAppletMgr Client COM Automation Class
CCMUpdatesDeployment COM Automation Class
ICCMUpdatesDeployment::InstallUpdates Method