In System Center 2012 R2 Configuration Manager, you enable or disable the Desired Configuration Management Client Agent by modifying the site control file settings.

To enable or disable the Desired Configuration Management Client Agent

  1. Set up a connection to the SMS Provider.

  2. Make a connection to the Desired Configuration Management Client Agent section of the site control file by using the SMS_SCI_ClientComp class.

  3. Loop through the array of available properties, making changes as needed.

  4. Commit the changes to the site control file.

Example

The following example method enables or disables the Desired Configuration Management Client Agent by using the SMS_SCI_ClientComp class to connect to the site control file and change the Flag property.

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

Visual Basic Script  Copy Code
Sub EnableDisableDCMClientAgent(swbemServices,   _ 
								swbemContext, _
								siteCode, 	_
								enableDisableFlag)

' 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)

' Display DCM client agent settings before change.
Wscript.Echo " "
Wscript.Echo "Properties - Before Change"
Wscript.Echo "---------------------------"
Wscript.Echo swbemInst.ClientComponentName
Wscript.Echo swbemInst.Flags & " (0 = Disabled, 1 = Enabled)"

' Set DCM client agent by setting flags value to  0 or 1 using the enableDisableFlag variable.
swbemInst.Flags = enableDisableFlag

' Save new client agent settings.
swbemInst.Put_ , swbemContext
swbemServices.ExecMethod "SMS_SiteControlFile.Filetype=1,Sitecode=""" & siteCode & """", "Commit", , , swbemContext
Set swbemInst = Nothing

' 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 = swbemServices.Get("SMS_SCI_ClientComp.Filetype=1,Itemtype='Client Component',Sitecode='" & siteCode & "',ItemName='Configuration Management Agent'", , swbemContext)

' Display DCM client agent settings after change.
Wscript.Echo " "
Wscript.Echo "Properties - After Change"
Wscript.Echo "---------------------------"
Wscript.Echo swbemInst.ClientComponentName
Wscript.Echo swbemInst.Flags & " (0 = Disabled, 1 = Enabled)"

Set swbemInst = Nothing

End Sub
C#  Copy Code
public void EnableDisableDCMClientAgent(WqlConnectionManager connection,
										string siteCode,
										string enableDisableFlag)
{

	try
	{
		IResultObject siteDefinition = connection.GetInstance(@"SMS_SCI_ClientComp.FileType=1,ItemType='Client Component',SiteCode='" + siteCode + "',ItemName='Configuration Management Agent'");
					
		// Display DCM client agent settings before change.
		Console.WriteLine();
		Console.WriteLine("Properties - Before Change");
		Console.WriteLine("---------------------------");
		Console.WriteLine(siteDefinition["ClientComponentName"].StringValue);
		Console.WriteLine(siteDefinition["Flags"].StringValue + " (0 = Disabled, 1 = Enabled)");

		// Set DCM client agent by setting flags value to  0 or 1 using the enableDisableFlag variable.
		siteDefinition["Flags"].StringValue = enableDisableFlag;

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

		// Verify change by reconnecting and getting the value again.
		IResultObject siteDefinition2 = connection.GetInstance(@"SMS_SCI_ClientComp.FileType=1,ItemType='Client Component',SiteCode='" + siteCode + "',ItemName='Configuration Management Agent'");
	
		// Display DCM client agent settings after change.
		Console.WriteLine();
		Console.WriteLine("Properties - After Change");
		Console.WriteLine("--------------------------");
		Console.WriteLine(siteDefinition2["ClientComponentName"].StringValue);
		Console.WriteLine(siteDefinition2["Flags"].StringValue + " (0 = Disabled, 1 = Enabled)");
					
}
	
	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.

swbemContext

  • VBScript: SWbemContext

A valid context object. For more information, see How to Add a Configuration Manager Context Qualifier by Using WMI.

siteCode

  • Managed: String

  • VBScript: String

The site code.

enableDisableFlag

  • Managed: String

  • VBScript: String

Determines whether the Desired Configuration Management Client Agent is enabled or disabled.

0 - disabled

1 - enabled

Compiling the Code

This C# example requires:

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