SMS SDK Tips: When and How to use SMSContext

SMSContext is a SWbemNamedValueSet( SWbemNamedValueSetare used principally to send more information to providers when submitting certain calls to WMI. In most cases, you don’t need to set SMSContext when making WMI calls. But providing SMSContext will introduce benefit like the status messages will contain more information like from which application and on which machine is this WMI call be made. However if you deal with Site Control File classes, you will have to use SMS context since SessionHandler is required for Site Control File oprations.

What contexts are needed for a well behaved SMS SDK application

Why it is necessary

Sample Code:

Dim SMSContext = CreateObject("WbemScripting.SWbemNamedValueSet")


LocaleID is used for code page conversion

Auto Localization properties fall back:

For properties that have localized values in the database, backend will try to get the property value for Locale of LocaleID

SMSContext.Add "LocaleID", "MS\1033"


This is localized value.

Used for audit status messages. So SMS Admins can tell what sms application have made all the changes

SMSContext.Add "ApplicationName", "MyApp"


Used for audit status messages. So SMS Admins can tell from what machines the changes have made.

SMSContext.Add "MachineName", "MyMachine"


This is required if there is Site control file operation, and the value should be returned from call SMS_SiteControlFile::GetSesssionHandle

When the application closes, call SMS_SiteControlFile::ReleaseSesssionHandle

NOTE: Without the session handle in the context, the SCF operation will be on the default session-less site control file copy.

Set Services = GetObject("winmgmts:root/sms/site_<sitecode>")


Set SCF = Services.Get("SMS_SiteControlFile")

SCF.GetSessionHandle SessionHandle SMSContext.Add "SessionHandle", SessionHandle


This is recommended for performance optimization


Site control file classes (SMS_SCI_...) are different from other SMS Classes in that the server side keeps a copy of the site control file object, when IWbemServices::PutInstance is called, it does not save the object to the database directly like the other SMS classes such as SMS_Package, instead, it is save`d into the in-memory copy of the site control file. It is saved to the database until SMS_SiteControlFile::CommitSCF is called.