Partager via


How to Synchronize with the Software Update Point

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 synchronize the software update point, in Microsoft System Center Configuration Manager 2007, by modifying the Sync Now property in the site control file.

To synchronize the software update point

  1. Set up a connection to the SMS Provider.

  2. Make a connection to the SMS_WSUS_SYNC_MANAGER component section of the site control file using the SMS_SCI_Component class.

  3. Calculate the current timestamp (number of seconds from 1/1/1970 to current Coordinated Universal Time (UTC) time).

  4. Replace the Sync Now value with the current timestamp.

  5. Commit the property changes to the site control file.

Example

The following example method shows how to synchronize the software update point by modifying the site control file.

Note

The following methods are the equivalent of initiating a software update point synchronization manually. When synchronization is initiated manually, only software updates metadata that is new since the last synchronization is inserted into the site database.

Important

The following VBScript example uses a very simple calculation to get the UTC time offset. You might want to add a more robust solution to calculate the necessary value.

For information about calling the sample code, see Calling Configuration Manager Code Snippets.

Sub SynchronizeSoftwareUpdatePoint(swbemServices,         _
                                   swbemContext,          _
                                   siteCode)

    ' Load site control file and get the SMS_WSUS_SYNC_MANAGER component section.
    swbemServices.ExecMethod "SMS_SiteControlFile.Filetype=1,Sitecode=""" & siteCode & """", "Refresh", , , swbemContext
        
    ' Calculate the current timestamp (number of seconds from 1/1/1970 to current time UTC).
    calculatedUTCOffsetinSeconds = (8 * 60 * 60)
    currentTimestamp = datediff("s", "1/1/1970 12:00:00 AM", now()) + calculatedUTCOffsetinSeconds

    
    Query = "SELECT * FROM SMS_SCI_Component " & _
            "WHERE ComponentName = 'SMS_WSUS_SYNC_MANAGER' " & _
            "AND SiteCode = '" & siteCode & "'"
    
    Set SCIComponentSet = swbemServices.ExecQuery(Query, ,wbemFlagForwardOnly Or wbemFlagReturnImmediately, swbemContext)
                       
    ' Only one instance is returned from the query.
    For Each SCIComponent In SCIComponentSet

        ' Loop through the array of embedded SMS_EmbeddedProperty instances.
        For Each vProperty In SCIComponent.Props         
                            
            ' Setting: Sync Now
            If vProperty.PropertyName = "Sync Now" Then
                
                ' Modify the value.
                vProperty.Value = currentTimestamp
                wscript.echo "New value " & currentTimestamp
                
                ' Output success message.
                wscript.echo " "
                wscript.echo "Reset 'Sync Now' property with current timestamp. "               

            End If
               
        Next   

             ' Update the component in your copy of the site control file. Get the path
             ' to the updated object, which could be used later to retrieve the instance.
             Set SCICompPath = SCIComponent.Put_(wbemChangeFlagUpdateOnly, swbemContext)
    Next
                          
    ' Commit the change to the actual site control file.
    Set InParams = swbemServices.Get("SMS_SiteControlFile").Methods_("CommitSCF").InParameters.SpawnInstance_
    InParams.SiteCode = siteCode
    swbemServices.ExecMethod "SMS_SiteControlFile", "CommitSCF", InParams, , swbemContext
      
    ' Release copy of the site control file.
    swbemServices.Get("SMS_SiteControlFile").ReleaseSessionHandle swbemContext.Item("SessionHandle").Value

End Sub
public void SynchronizeSoftwareUpdatePoint(WqlConnectionManager connection,
                                    string siteCode,
                                    string SUPServerName)
{

    // Calculate the current timestamp (number of seconds from 1/1/1970 to current time UTC).
    DateTime baseTimeValue = new DateTime(1970, 1, 1);
    DateTime currentDateTime = DateTime.UtcNow;
    TimeSpan calculatedTimeStamp = currentDateTime.Subtract(baseTimeValue);
    int currentTimestamp = Convert.ToInt32(calculatedTimeStamp.TotalSeconds);
            
    try
    {
        // Connect to SMS_WSUS_SYNC_MANAGER section of the site control file.
        IResultObject siteDefinition = connection.GetInstance(@"SMS_SCI_Component.FileType=2,ItemType='Component',SiteCode='" + siteCode + "',ItemName='SMS_WSUS_SYNC_MANAGER|" + SUPServerName + "'");
        foreach (KeyValuePair<string, IResultObject> kvp in siteDefinition.EmbeddedProperties)
        {
            // Temp copy of the embedded properties.
            Dictionary<string, IResultObject> embeddedProperties = siteDefinition.EmbeddedProperties;

            // Setting: Sync Now.
            if (kvp.Value.PropertyList["PropertyName"] == "Sync Now")
            {            
                // Change Sync Now value to current timestamp which will initiate WSUS sync.
                embeddedProperties["Sync Now"]["Value"].StringValue = currentTimestamp.ToString();
       
                // Output message on successful change.
                Console.WriteLine("Reset 'Sync Now' property with current timestamp.");
            }
                                
            // Store the settings that have changed.
            siteDefinition.EmbeddedProperties = embeddedProperties;
        }

        // Save the settings.
        siteDefinition.Put();

    }
    catch (SmsException ex)
    {
        Console.WriteLine("Failed. Error: " + ex.InnerException.Message);
        throw;
    }
}

The example method has the following parameters:

Parameter

Type

Description

connection

  • Managed: WqlConnectionManager

  • VBScript: SWbemServices

A valid connection to the SMS Provider.

siteCode

  • Managed: String

  • VBScript: String

The site code.

Compiling the Code

The C# example has the following compilation requirements:

Namespaces

System

System.Collections.Generic

System.Text

Microsoft.ConfigurationManagement.ManagementProvider

Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

Assembly

adminui.wqlqueryengine

microsoft.configurationmanagement.managementprovider

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
Synchronizing the Software Update Point
About the Configuration Manager Site Control File
How to Read and Write to the Configuration Manager Site Control File by Using Managed Code
How to Read and Write to the Configuration Manager Site Control File by Using WMI
SMS_SCI_Component Server WMI Class
How to Add a Configuration Manager Context Qualifier by Using WMI