Determining the Current Synchronization Settings
Applies To: Windows Server Update Services
The following example shows how to retrieve the current synchronization-related settings. 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 Windows Server Update Services 3.0 Class Library).
using System;
using System.Collections.Specialized; //StringCollection
using Microsoft.UpdateServices.Administration; //WSUS API
IUpdateServerConfiguration configuration = null;
ISubscription subscription = null;
UpdateCategoryCollection categories = null;
UpdateClassificationCollection classifications = null;
Boolean storedOnMU = false;
Boolean syncFromMU = false;
//These two objects contain the properties and methods for
//retrieving synchronization settings.
configuration = server.GetConfiguration();
subscription = server.GetSubscription();
Console.WriteLine("Current Subscription Settings:\n");
//Store update files locally or on Microsoft Update?
storedOnMU = configuration.HostBinariesOnMicrosoftUpdate;
Console.WriteLine("Store update files {0}.",
(storedOnMU) ? "on Microsoft Update" : "locally");
if (false == storedOnMU) //Files are stored locally.
{
//Does WSUS download all update files or only those that are currently approved for installation?
Console.WriteLine("Download {0}.",
(configuration.DownloadUpdateBinariesAsNeeded) ?
"only updates that are approved for installation" :
"all update files");
//Does WSUS download express installation update files if available?
if (true == configuration.DownloadExpressPackages)
{
Console.WriteLine("Download the update files as express installation files, if available.");
}
}
//In which languages are the update files downloaded?
if (true == configuration.AllUpdateLanguagesEnabled)
{
Console.WriteLine("The update files and metadata are downloaded for all languages.");
}
else
{
StringCollection enabledLanguages = configuration.GetEnabledUpdateLanguages();
Console.WriteLine("Download the update files and metadata for the following languages:");
foreach (String language in enabledLanguages)
{
Console.WriteLine(" {0}", language);
}
}
//Which categories of products does WSUS synchronize?
categories = subscription.GetUpdateCategories();
Console.WriteLine("Synchronize the following categories of product updates:");
if (0 == categories.Count)
{
Console.WriteLine(" No update categories are selected");
}
else
{
foreach (IUpdateCategory category in categories)
{
if (UpdateCategoryType.Product == category.Type)
Console.WriteLine(" {0}", category.Title);
else
Console.WriteLine(" All {0} products", category.Title); //Microsoft Corporation or Windows
}
}
//Which classifications of updates does WSUS synchronize?
classifications = subscription.GetUpdateClassifications();
Console.WriteLine("Synchronize the following classification of product updates:");
if (0 == classifications.Count)
{
Console.WriteLine(" No update classifications are selected");
}
else
{
foreach (IUpdateClassification classification in classifications)
{
Console.WriteLine(" {0}", classification.Title);
}
}
//Synchronize from Microsoft Update or an upstream server?
syncFromMU = configuration.SyncFromMicrosoftUpdate;
Console.WriteLine("Synchronize updates from {0}",
(syncFromMU) ? "Microsoft Update." : "the following upstream WSUS server:");
if (false == syncFromMU)
{
Console.WriteLine(" {0}", configuration.UpstreamWsusServerName);
Console.WriteLine("\nThis server is {0}",
(configuration.IsReplicaServer) ? "a replica downstream server." :
"an autonomous downstream server.");
}
//Synchronize automatically or manually?
if (true == subscription.SynchronizeAutomatically)
{
DateTime syncHour = DateTime.Today + subscription.SynchronizeAutomaticallyTimeOfDay;
Console.WriteLine("Synchronize at {0} every day.", syncHour.ToLocalTime().ToShortTimeString());
}
else
{
Console.WriteLine("The Administrator manually starts the synchronization process.");
}