Partilhar via


How to Write a Configuration Manager Site Control File Embedded RegMultiString 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 RegMultiString list to a site control file component or configuration resource by creating a SMS_Client_Reg_MultiString_List and adding it to the resource's RegMultiStringLists array property.

Warning

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

To write a RegMultiString 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_Client_Reg_MultiString_List for the required embedded property.

  4. Update the embedded property.

  5. 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 RegMultiString list to a supplied site control file resource component or configuration resource (resource). The example works by finding the embedded RegMultiString list (valuetName) in the resource and then by replacing the existing values array (ValueStrings) with the supplied values array (valueStrings). If you want to add an item to an existing property values array, you must 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 the 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 WriteScfRegMultiStringList(connection,  _
                                    context,    _
                                    resource,   _
                                    valueName,  _
                                    valueStrings)
     Dim vRegMultiStringLists 
     Dim vRegMultiStringList 
     
     ' Are there any reg multi strings in the array?
     If  IsNull(resource.RegMultiStringLists) =  False Then
     
        ' Walk through the RegMultiStringLists in the SCI.
        For Each vRegMultiStringList In resource.RegMultiStringLists
     
            ' Is this the item you're looking for?
            If LCase(vRegMultiStringList.ValueName) = LCase(valueName) Then
            
                ' Set the new values.
                vRegMultiStringList.ValueStrings = valueStrings
                resource.Put_,context
                ' You're done, so exit.
                Exit Sub
            End If
        Next 
    End If
    
    ' No Item was found, so create it.
    
    ' Create the new reg multi string list.
    Dim regMultiStringList 
    Set regMultiStringList = connection.Get("SMS_Client_Reg_MultiString_List").SpawnInstance_
    
    ' Set the properties of the new instance.
    regMultiStringList.ValueName = valueName
    regMultiStringList.ValueStrings = valueStrings
    
    ' Do you need to create a new array or resize the existing one?
    If ISNull(resource.RegMultiStringLists) = True Then
        
        ' Create a new array.
        resource.RegMultiStringLists = Array(regMultiStringList)
    
    Else
        ' Grow the array by 1.
        vRegMultiStringLists = resource.RegMultiStringLists
        ReDim Preserve vRegMultiStringLists(UBound(vRegMultiStringLists) + 1)
        
        ' Add the new item.
        Set vRegMultiStringLists(UBound(vRegMultiStringLists)) = regMultiStringList
        resource.RegMultiStringLists = vRegMultiStringLists
    End If
    
    resource.Put_,context
End Sub
public void WriteScfRegMultiStringList(
IResultObject resource,
string valueName,
ArrayList valueStrings)
{
    try
    {
        Dictionary<string, IResultObject> regMultiStringLists =  regMultiStringLists = resource.RegMultiStringLists;
        
        // Get the property, or create it.
        IResultObject ro;
        if (regMultiStringLists.ContainsKey(valueName))
        {
            ro = regMultiStringLists[valueName];
        }
        else
        {
            ConnectionManagerBase connection = resource.ConnectionManager;
            ro = connection.CreateEmbeddedObjectInstance("SMS_Client_Reg_MultiString_List");
            regMultiStringLists.Add(valueName, ro);
        }

        ro["ValueName"].StringValue = valueName;
        ro["ValueStrings"].StringArrayValue = (string[])valueStrings.ToArray(typeof(string));

        resource.RegMultiStringLists = regMultiStringLists;

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

The example method has the following parameters:

Parameter

Type

Description

Resource

  • Managed: IResultObject

  • VBScript: SWbemObject

The site control file resource that contains the RegMultiString list.

ValueName

  • Managed: Integer

  • VBScript: Integer

The RegMultiString list name. It is obtained from the SMS_Client_Reg_MultiString_List class ValueName property.

ValueStrings

  • Managed: String

  • VBScript: String

The RegMultiString list. It is obtained from the SMS_Client_Reg_MultiString_List class ValueStrings property.

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

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