Compartir a través de


How to Add a Configuration Manager Context Qualifier by Using WMI

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 add context qualifiers to a connection (SWbemServices) or object (SWbemObject) by creating a SWbemNamedValueSet value set to hold the context qualifiers. You then provide the SWbemNamedValueSet value set as a parameter to connection and object methods.

In Configuration Manager 2007, you can provide your application name (ApplicationName), computer name (Machine Name) and locale identifier (LocaleID).

In most cases, context qualifiers are not required. The main exception is accessing the site control file where they are needed to set up session information. For more information, see About the Configuration Manager Site Control File.

To add a Configuration Manager context qualifier

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

  2. Create a WbemScripting.SWbemNamedValueSet object and add the desired context qualifiers.

  3. Use the SWbemNamedValue value set you created in step two to pass context qualifiers to connection and object manipulation calls.

Example

The following VBScript example creates a SWbemNamedValueSet value set and adds the supplied context qualifiers. The following code example demonstrates how to call the method for use in an SMS_Package package object Put method call. For more information about Configuration Manager objects, see About Configuration Manager Objects.

Dim context

Set context = CreateContextQualifiers("My application" , "My Computer" , "MS\1033")

package.Put_ , context

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

Function CreateContextQualifiers(applicationName, machineName, localeID)
    On Error Resume next
    Dim smsContext
    
    set smsContext = CreateObject("WbemScripting.SWbemNamedValueSet")

    ' Add the context qualifiers to the set.
    smsContext.Add "LocaleID", localeID
    smsContext.Add "MachineName", machineName
    smsContext.Add "ApplicationName", applicationName
   
    Set CreateContextQualifiers = smsContext
    
      If Err.Number<>0 Then
        WScript.Echo Err.Description
        CreateContextQualifiers = null
        Exit Function
    End If
End Function

The example method has the following parameters:

Parameter Type Description

applicationName

  • String

The ApplicationName context qualifier.

machineName

  • String

The machine name qualifier.

localeID

  • String

The locale identifier. For example, MS\1033 is English (U.S.). If you need the locale for non-U.S. installations, you can get it from the SMS_Identification Server WMI ClassLocaleID property.

Compiling the Code

This VBScript example requires:

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

Concepts

About the Configuration Manager Site Control File
About Configuration Manager Objects
Configuration Manager Context Qualifiers
How to Connect to an SMS Provider in Configuration Manager by Using WMI

Other Resources

https://go.microsoft.com/fwlink/?LinkId=43950