In System Center 2012 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 System Center 2012 Configuration Manager, 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
-
Set up a connection to the SMS Provider. For more information, see About the SMS Provider in Configuration Manager.
-
Create a WbemScripting.SWbemNamedValueSet object and add the desired context qualifiers.
-
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.
Visual Basic Script | Copy Code |
---|---|
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 |
|
The ApplicationName context qualifier. |
machineName |
|
The machine name qualifier. |
localeID |
|
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 Securing Configuration Manager Applications.