How to Add a Configuration Manager Context Qualifier by Using WMI

In Configuration Manager, 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, you can provide your application name (ApplicationName), computer name (MachineName) 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 SMS Provider fundamentals.

  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 Objects overview.

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

.NET Framework Security

For more information about securing Configuration Manager applications, see Configuration Manager role-based administration.

See Also

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