Freigeben über


How to Write a Configuration Manager Site Control File Embedded Property List

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, you write an embedded property list to a site control file resource by either updating the property list if it already exists, or by creating and adding a new property list to the resource's list of properties.

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

Value Description

PropertyListName

The embedded property name.

Values

An array of string values. Each array item represents a single property list item.

Warning

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 list

  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_EmbeddedPropertyList for the required embedded property list or, if it does not exist, create the SMS_EmbeddedPropertyList object.

  4. Populate the SMS_EmbeddedPropertyList object.

  5. Update the resources property lists with the SMS_EmbeddedPropertyList 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 list to a supplied site control file resource (resource). The example works by finding the embedded property list (propertyListName) in the resource and then by replacing the existing values array with the supplied values array (values). If you want to add an item to an existing property values array, you will need to first get the array, resize it, and the add the new array element.

If the embedded property list does not exist, it is created, and then added to the list of existing resource embedded property list.

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.

Sub WriteScfEmbeddedPropertyList(connection,     _
    context,                             _
    resource,                           _
    propertyListName,                    _
    values)

    Dim found
    Dim vProperty
     
    found = false

    For each vProperty in resource.PropLists
       if   UCase(vProperty.PropertyListName) = UCase(propertyListName) Then
            ' Found property, so add the property list.
            vProperty.Values = values
             resource.Put_ , context
            found = true
        End If
     Next  
                   
     If found = False Then
        ' Property list does not exist, so create it.
        Dim embeddedPropertyList
        Set embeddedPropertyList = connection.Get("SMS_EmbeddedPropertyList").Spawninstance_()
        embeddedPropertyList.PropertyListName = propertyListName
        embeddedPropertyList.Values = values
        
        ' If needed, create the property list array.
        If ISNull (resource.PropLists) Then
            resource.PropLists = array(embeddedPropertyList)
        Else
           ' Add property list to existing property lists.
            dim propertyList
            propertyList = resource.PropLists
            redim preserve propertyList(Ubound (propertyList) +1)
            Set propertyList(Ubound(propertyList)) = embeddedPropertyList
            resource.Proplists = propertyList
        End If
        resource.Put_,context    
    End If 
End Sub          
public void WriteScfEmbeddedPropertyList(
    IResultObject resource,
    string propertyListName,
    ArrayList values
    )
{
    try
    {

        Dictionary<string, IResultObject> EmbeddedPropertyList = resource.EmbeddedPropertyLists;

        // Get the property list, or create it. 
        IResultObject ropl;
        if (EmbeddedPropertyList.ContainsKey(propertyListName))
        {
            ropl = EmbeddedPropertyList[propertyListName];
        }
        else
        {
            ConnectionManagerBase connection = resource.ConnectionManager;
            ropl = connection.CreateEmbeddedObjectInstance("SMS_EmbeddedPropertyList");
            EmbeddedPropertyList.Add(propertyListName, ropl);
        }

        // Set the property list properties.
        ropl["PropertyListName"].StringValue = propertyListName;
        ropl["Values"].StringArrayValue = (string[])values.ToArray(typeof(string));
        resource.EmbeddedPropertyLists = EmbeddedPropertyList;

        resource.Put();
    }
    catch (SmsException e)
    {
        Console.WriteLine("Failed to write property list: " + 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.

swbemContext (VBScript)

  • VBScript: SWbemContext

A valid context object. For more information, see How to Read and Write to the Configuration Manager Site Control File by Using WMI.

Resource

  • Managed: IResultObject

  • VBScript: SWbemObject

The site control file resource that contains the embedded property.

propertyListName

  • Managed: String

  • VBScript: String

The embedded property list to be written to.

Values

  • Managed: String array

  • VBScript: String array

The SMS_EmbeddedProperty class Values property. An array of string values.

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

Tasks

How to Write a Configuration Manager Site Control File Embedded Property

Concepts

About the Configuration Manager Site Control File
How to Read a Configuration Manager Site Control File Embedded Property
How to Read a Configuration Manager Site Control File Embedded Property List
How to Read a Configuration Manager Site Control File Embedded RegMultiString List
How to Write a Configuration Manager Site Control File Embedded RegMultiString List
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