Displaying Available Updates

To retrieve all updates, call GetUpdates. The UpdateCollection that is returned contains updates from all categories and classifications, updates that supersede other updates, and declined updates. If you want to retrieve a subset of updates, for example, retrieve only approved updates, call GetUpdates where you set the ApprovedStates property of the UpdateScope to ApprovedStates.LatestRevisionApproved.

The following example shows how to retrieve all updates that were not declined or superseded. The example indicates if the update is approved or has revisions or related updates that are approved.

IUpdateServer server = AdminProxy.GetUpdateServer();

//Retrieve all the latest updates.  
foreach (IUpdate update in server.GetUpdates())
{
  //If the update is not superseded by other related updates and is not declined,
  //determine if the update is approved or not.
  if (false == update.IsSuperseded && false == update.IsDeclined) 
  {
    Console.WriteLine("\n{0}", update.Title);

    if (update.IsApproved)
    {
      //If the update is approved, determine the action and to which
      //groups the update is approved.
      foreach (IUpdateApproval approval in update.GetUpdateApprovals())
      {
        Console.WriteLine("  This update is approved for {0} to {1}.", 
                          approval.Action,
                          approval.GetComputerTargetGroup().Name);
      }
    }
    else
    {
      Console.WriteLine("  This update is not approved.");
    }

    //If the update has previous revisions, determine if any of them are approved.
    if (update.IsLatestRevision && update.HasStaleUpdateApprovals)
    {
      Console.WriteLine("  The following earlier revisions of this update are approved:");
      foreach (IUpdate revision in update.GetRelatedUpdates(UpdateRelationship.AllRevisionsOfThisUpdate))
      {
        if (revision.IsApproved)
          Console.WriteLine("    {0}", revision.Title);
      }
    }

    //Retrieve updates that are superseded by this update. If the update or one of its revisions
    //is approved, list the update.
    UpdateCollection supersededUpdates = update.GetRelatedUpdates(UpdateRelationship.UpdatesSupersededByThisUpdate);
    if (supersededUpdates.Count > 0)
    {
      Console.WriteLine("  The following superseded updates are also approved:");
      foreach (IUpdate supersededUpdate in supersededUpdates)
      {
        if (supersededUpdate.IsApproved || supersededUpdate.HasStaleUpdateApprovals)
        {
          Console.WriteLine("    {0}", supersededUpdate.Title);
        }
      }
    }
      
  }
}

Show:
© 2014 Microsoft