In Microsoft System Center Configuration Manager 2007, you write an embedded property to a site control file resource by either updating the property's SMS_EmbeddedObject object if it already exists, or by creating and adding a new SMS_EmbeddedObject object property to the resource's array of properties (Props parameter).

An embedded property has the following properties that you can set. For more information, see SMS_EmbeddedProperty.

Value Description

PropertyName

The embedded property name.

Value

An integer value

Value1

A string value

Value2

A string value

Caution
Making changes to the site control file can cause irreparable damage to your Configuration Manager 2007 site.

To write a site control file embedded property

  1. Set up a connection to the SMS Provider. For more information, see About the SMS Provider in Configuration Manager.

  2. Using the connection object from step one, get a site control file resource. For more information, see About the Configuration Manager Site Control File.

  3. Get the SMS_EmbeddedProperty for the required embedded property or, if it does not exist, create the SMS_EmbeddedProperty object.

  4. Populate the SMS_EmbeddedObject object.

  5. Update the resources properties with the SMS_EmbeddedObject object.

  6. Commit the changes to the site control file. For more information, see About the Configuration Manager Site Control File.

Example

The following example method writes an embedded property to a supplied site control file resource. The example works by finding the embedded property in the resource and then by updating the embedded property details. If the embedded property does not exist, it is created, and then added to the list of existing resource embedded properties.

To view code that calls these methods, see 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

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

Visual Basic Script  Copy Code
Sub WriteScfEmbeddedProperty(connection, _  
			context, 			_
			resource, 		 _
			propertyName, 	 _
			value, 			_
			value1, 			 _
			value2)		 
			
 
	Dim vProperty
	Dim found

	found = false

	For Each vProperty In resource.Props
		If UCase(vProperty.PropertyName) = UCase(propertyName) Then

			' Modify the values.
			vProperty.Value = value
			vProperty.Value1 = value1
			vProperty.Value2 = value2
			resource.Put_ , context
			found = true
		End If
	Next   
	
	If found = False Then
	
		' Property does not exist, so create it.
		Dim embeddedProperty
		Set embeddedProperty = connection.Get("SMS_EmbeddedProperty").Spawninstance_()
		embeddedProperty.PropertyName = propertyName
		embeddedProperty.Value = value
		embeddedProperty.Value1 = value1
		embeddedProperty.Value2 = value2
	
		' Add the property to the properties.
		' If the props array doesn't exist, create it.
		If ISNull (resource.Props) Then
			resource.Props = array(embeddedProperty)
		Else   
			' Grow the array and add the property.
			dim properties
			properties = resource.Props
			Redim Preserve properties(UBound(properties) + 1)
			Set properties(UBound(properties)) = embeddedProperty
			resource.Props = properties
		End If 
		resource.Put_,context
	End If
End Sub
C#  Copy Code
public void WriteScfEmbeddedProperty(
	IResultObject resource,
	string propertyName,
	int value,
	string value1,
	string value2)
{
	try
	{

		// Properties
		Dictionary<string, IResultObject> EmbeddedProperties = resource.EmbeddedProperties;

		// Get the property, or create it.
		IResultObject ro;
		if (EmbeddedProperties.ContainsKey(propertyName))
		{
			ro = EmbeddedProperties[propertyName];
	}
		else
		{
			ConnectionManagerBase connection = resource.ConnectionManager;
			ro = connection.CreateEmbeddedObjectInstance("SMS_EmbeddedProperty");
			EmbeddedProperties.Add(propertyName, ro);
	}

		ro["PropertyName"].StringValue = propertyName;
		ro["Value"].IntegerValue = value;
		ro["Value1"].StringValue = value1;
		ro["Value2"].StringValue = value2;

		resource.EmbeddedProperties = EmbeddedProperties;

		// Commit the change.
		resource.Put();
}
	catch (SmsException e)
	{
		Console.WriteLine("Failed to write property: " + e.Message);
		throw;
}
}

The example method has the following parameters:

Parameter

Type

Description

Connection

  • Managed: WqlConnectionManager

  • VBScript: SWbemServices

A valid connection to the SMS Provider.

swbemContex (VBScript)t

  • VBScript: SWbemContext

A valid context object.

Resource

  • Managed: IResultObject

  • VBScript: SWbemObject

The site control file resource that contains the embedded property.

propertyName

  • Managed: String

  • VBScript: String

The embedded property to be written to.

Value

  • Managed: Integer

  • VBScript: Integer

The SMS_EmbeddedProperty class value property value.

Value1

  • Managed: String

  • VBScript:String

The SMS_EmbeddedProperty class value1 property value.

Value2

  • Managed: String

  • VBScript: String

The SMS_EmbeddedProperty class value2 property value.

Compiling the Code

The C# example has the following compilation requirements:

Namespaces

System

System.Collections.Generic

System.Collections

System.Text

Microsoft.ConfigurationManagement.ManagementProvider

Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

Assembly

microsoft.configurationmanagement.managementprovider

adminui.wqlqueryengine

Robust Programming

For more information about error handling, see About Configuration Manager Errors.

Security

For more information about securing Configuration Manager applications, see About Securing Configuration Manager Applications.

See Also


Send comments about this topic to Microsoft.