共用方式為


How to Read 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 read an embedded RegMultiString list from a site control file component or configuration resource by getting the RegMultiStringList SMS_Client_Reg_MultiString_List object from the resources RegMultiStringLists property array.

To read 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 RegMultiString list.

  4. View the RegMultiString list values in the SMS_Client_Reg_MultiString_ListValueStrings array property.

Example

The following example method populates the supplied valueStrings parameter with the value strings of the embedded RegMultiString list identified by the valueName parameter. true is returned if the RegMultiString list is found; otherwise, false is returned.

You can update the embedded RegMultiString list returned from this method by using the method How to Write a Configuration Manager Site Control File Embedded RegMultiString 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 or see 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.

Function GetScfRegMultiStringList(resource,  _
        valueName,                           _
        ByRef valueString) 
        
    dim regMultiStringList       
                
    If IsNull(resource.RegMultiStringLists) = True Then
            GetScfRegMultiStringList = false
            Exit Function
    End If    


    For Each regMultiStringList in resource.RegMultiStringLists
        if UCase(regMultiStringList.ValueName) = UCase(valueName) Then
            ' Found the property, so populate values and exit.
            valueName = regMultiStringList.ValueName 
            valueString = regMultiStringList.ValueStrings
            GetScfRegMultiStringList = True
            Exit Function
        End If    
    Next
    
    ' Did not find the string list.
    GetScfRegMultiStringList = False    
End Function
public bool GetScfRegMultiStringList(
IResultObject resource,
string valueName,
out ArrayList valueStrings)
{
    valueStrings = new ArrayList();
    
    try
    {
        if (resource.RegMultiStringLists.ContainsKey(valueName))
        {
            valueStrings.AddRange(resource.RegMultiStringLists[valueName]["ValueStrings"].StringArrayValue);
            return true;
        }
    }
    catch (SmsException e)
    {
        Console.WriteLine("Couldn't get multi-string list: " + e.Message);
    }
    return false;

}

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