Share via


Specifying Updates to Synchronize

 

Applies To: Windows Server Update Services

To download updates, you must first define your synchronization settings. The synchronization settings identify the types of updates that you want to make available to clients in your organization.

The synchronization settings specify:

The following example shows how to specify synchronization settings that synchronize and store approved, critical updates for clients on an upstream WSUS server. The server variable that is used in the example is an instance of IUpdateServer (for an example that retrieves an IUpdateServer instance and sets the preferred culture, see Using the WSUS 3.0 Class Library).

using System.Collections.Specialized;  //For StringCollection  
  
IUpdateServerConfiguration configuration = null;  
ISubscription subscription = null;  
  
//These two objects contain the properties and methods for   
//specifying synchronization settings.  
configuration = server.GetConfiguration();  
subscription = server.GetSubscription();  
  
//Store update files locally on the WSUS server.  
//Download only update files that are approved for installation.  
//Do not download express packages.  
configuration.HostBinariesOnMicrosoftUpdate = false;  
configuration.DownloadUpdateBinariesAsNeeded = true;  
configuration.DownloadExpressPackages = false;  
  
//Download the updates for English, French, and German languages.   
configuration.AllUpdateLanguagesEnabled = false;  
StringCollection enabledLanguages = new StringCollection();  
enabledLanguages.AddRange(new string[] {"en", "fr", "de"});  
configuration.SetEnabledUpdateLanguages(enabledLanguages);  
  
//Subscribe to receive Windows XP family updates.  
foreach (IUpdateCategory category in server.GetUpdateCategories())  
{  
  if (category.Title.ToLower() == "windows xp family")  
  {  
    UpdateCategoryCollection categories = new UpdateCategoryCollection();  
    categories.Add(category);  
    subscription.SetUpdateCategories(categories);  
    break;  
  }  
}  
  
//Subscribe to receive critical updates.  
foreach (IUpdateClassification classification in server.GetUpdateClassifications())  
{  
  if (classification.Title.ToLower() == "critical updates")  
  {  
    UpdateClassificationCollection classifications = new UpdateClassificationCollection();  
    classifications.Add(classification);  
    subscription.SetUpdateClassifications(classifications);  
    break;  
  }  
}  
  
//Synchronize updates every day at 20:00. WSUS stores UTC time, so convert the local time to UTC.  
subscription.SynchronizeAutomatically = true;  
DateTime localSyncHour = DateTime.Today + new TimeSpan(20,0,0);   
subscription.SynchronizeAutomaticallyTimeOfDay = localSyncHour.ToUniversalTime().TimeOfDay;  
  
//Synchronize from Microsoft Update.  
configuration.SyncFromMicrosoftUpdate = true;  
  
//Save configuration changes.  
//Make sure that the server is not busy before calling Save.  
UpdateServerConfigurationState state = configuration.GetUpdateServerConfigurationState();  
if (UpdateServerConfigurationState.Ready == state)  
{  
  configuration.Save();  
  
  //Save subscription changes.  
  subscription.Save();  
}  
else  
{  
  Console.WriteLine("WSUS database is busy. Please run later.");  
}  
  

To determine the current synchronization settings for a WSUS server, see Determining the Current Synchronization Settings.

To determine the progress of the synchronization process, see Determining the Progress or Status of the Synchronization Process.

To retrieve newly synchronized updates, see Reporting Newly Synchronized Updates.