Partager via


How to Configure the Default Compliance Evaluation Schedule

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

In Microsoft System Center Configuration Manager 2007, the site control file maintains configuration for the configuration of the site. These code samples query for the specific site control file item Configuration Management Agent, and change the EvaluationSchedule value to set the client agent evaluation schedule.

Details about reading from and writing to the site control file are discussed in the Configuration Manager Site Control File section of the SDK.

Warning

You should be experienced in managing a site's configuration before using the SMS Provider classes to modify the site configuration. You should use caution or avoid using the SMS_SCI_FileDefinition and SMS_SCI_SiteDefinition classes altogether. These classes manage the site control file itself. You can cause significant damage to a site by changing some configurable items.

Example

The following code example shows how to change the default compliance evaluation schedule for the configuration management client agent.

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

Sub ChangeDCMAgentEvaluationSchedule(swbemServices,    _
                                     swbemContext,     _
                                     siteCode,         _
                                     newAgentSchedule)

    ' The evaluation schedule is defined by a string stored in a schedule token format. 
    ' Detailed information on the schedule token format can be found in the class SMS_ScheduleToken reference material.

    ' Load site control file and get DCM client component section.
swbemServices.ExecMethod "SMS_SiteControlFile.Filetype=1,Sitecode=""" & siteCode & """", "Refresh", , , swbemContext
Set swbemInst = swbemServices.Get("SMS_SCI_ClientComp.Filetype=1,Itemtype='Client Component',Sitecode='" & siteCode & "',ItemName='Configuration Management Agent'", , swbemContext)

    ' Loop through the array of embedded SMS_EmbeddedProperty instances for the 
    ' Number of Retries PropertyName. Get its value and display it.
    For Each vProperty In swbemInst.Props
        
        If vProperty.PropertyName = "EvaluationSchedule" Then
        
            ' Display DCM client agent evaluation schedule before change.
            Wscript.Echo " "
            Wscript.Echo "Evaluation Schedule - Before Change"
            Wscript.Echo "-----------------------------------"
            Wscript.Echo vProperty.Value2
            
            ' Set DCM client agent evaluation schedule using the newAgentSchedule variable.
            vProperty.Value2 = newAgentSchedule
            
            ' Save new client agent settings
            swbemInst.Put_ , swbemContext
            swbemServices.ExecMethod "SMS_SiteControlFile.Filetype=1,Sitecode=""" & siteCode & """", "Commit", , , swbemContext

        End If
    Next

    ' Refresh in-memory copy of the site control file and get the DCM client component section.
swbemServices.ExecMethod "SMS_SiteControlFile.Filetype=1,Sitecode=""" & siteCode & """", "Refresh", , , swbemContext
Set swbemInst = Nothing

Set swbemInst = swbemServices.Get("SMS_SCI_ClientComp.Filetype=1,Itemtype='Client Component',Sitecode='" & siteCode & "',ItemName='Configuration Management Agent'", , swbemContext)

    For Each vProperty In swbemInst.Props
        
        If vProperty.PropertyName = "EvaluationSchedule" Then
        
            ' Sisplay DCM client agent evaluation schedule before change.
            Wscript.Echo " "
            Wscript.Echo "Evaluation Schedule - After Change"
            Wscript.Echo "----------------------------------"
            Wscript.Echo vProperty.Value2
                 
        End If
    Next

    ' Release copy of the site control file.
swbemServices.Get("SMS_SiteControlFile").ReleaseSessionHandle swbemContext.Item("SessionHandle").Value
Set swbemInst = Nothing

End Sub
public void ChangeDCMAgentEvaluationSchedule(WqlConnectionManager connection,
                                             string siteCode,
                                             string newAgentSchedule)
{

    // The evaluation schedule is defined by a string stored in a schedule token format. 
    // Detailed information on the schedule token format can be found in the class SMS_ScheduleToken reference material.

    try
    {
        IResultObject siteDefinition = connection.GetInstance(@"SMS_SCI_ClientComp.FileType=1,ItemType='Client Component',SiteCode='" + siteCode + "',ItemName='Configuration Management Agent'");

        if (siteDefinition.EmbeddedProperties.ContainsKey("EvaluationSchedule"))
        {
            Dictionary<string, IResultObject> WorkingEmbeddedProperties = siteDefinition.EmbeddedProperties; //get temporary copy

            // Display DCM client agent settings before change.
            Console.WriteLine();
            Console.WriteLine("DCM Client Agent Schedule - Before Change");
            Console.WriteLine("-----------------------------------------");             
            Console.WriteLine("Schedule in token format: " + WorkingEmbeddedProperties["EvaluationSchedule"]["Value2"].StringValue);

            // Set DCM client agent setting to new value.
            WorkingEmbeddedProperties["EvaluationSchedule"]["Value2"].StringValue = newAgentSchedule; 
            siteDefinition.EmbeddedProperties = WorkingEmbeddedProperties;
            
            // Save the settings.
            siteDefinition.Put();

            // Verify change by reconnecting and getting the value again.
            Dictionary<string, IResultObject> WorkingEmbeddedProperties2 = siteDefinition.EmbeddedProperties; //Get temporary copy for change verification.

            // Display DCM client agent settings after change.
            Console.WriteLine();
            Console.WriteLine("DCM Client Agent Schedule - After Change");
            Console.WriteLine("-----------------------------------------");
            Console.WriteLine("Schedule in token format: " + WorkingEmbeddedProperties2["EvaluationSchedule"]["Value2"].StringValue);

        }
    }

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

}

Compiling the Code

Namespaces

System

System.Collections.Generic

System.ComponentModel

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

About Desired Configuration Management Setup and Configuration
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_ClientComp Server WMI Class
Configuration Manager Schedules
How to Create a Schedule Token