How to Add Assignments to an SMS Advertisement

Published : April 11, 2005

The dates and times that SMS advertisement objects (SMS_Advertisement) can be assigned to run are stored as an array of objects. The objects are based on one of the classes, which are based on the SMS_ScheduleToken class. Adding or removing assignments requires adding or removing objects from that array. This example shows how to add an assignment to an existing advertisement.

Some properties in other SMS classes are also arrays of objects. The technique described in this example can be used in other situations.

On This Page

Example
Compiling the Code
See Also

Example

Dim objSWbemLocator
Dim objSWbemServices
Dim ProviderLoc
Dim AdvertisementID
Dim Location
Dim objAdvertisement
Dim i
Dim newST
Dim array()
AdvertisementID="99999999" 'Provide the required advertisement identifier here
 
'Connect to provider namespace for local computer.
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
 
Set objSWbemServices= objSWbemLocator.ConnectServer(".", "root\sms")
 
Set ProviderLoc = objSWbemServices.InstancesOf("SMS_ProviderLocation")
 
For Each Location In ProviderLoc
        If Location.ProviderForLocalSite = True Then
            Set objSWbemServices = objSWbemLocator.ConnectServer _
                 (Location.Machine, "root\sms\site_" + Location.SiteCode)
        End If
Next
 
Set objAdvertisement = objSWbemServices.Get("SMS_Advertisement.AdvertisementID='" & AdvertisementID & "'")
 
'Copy the current assigned schedule array to a local array that is one 
'bigger than the current assigned schedule array.
 
redim array( UBound(objAdvertisement.AssignedSchedule)+1 )
For i=0 to UBound( objAdvertisement.assignedSchedule )
  Set array(i) = objAdvertisement.AssignedSchedule(i)
Next
 
'Create an assignment.
Set newST = objSWbemServices.Get("SMS_ST_RecurInterval").SpawnInstance_()
newST.DayDuration=20
newST.DaySpan=10
'Add the new assignment to the end of the local array.
Set array( UBound(array) ) =newST
 
objAdvertisement.AssignedSchedule = array
 
objAdvertisement.Put_

Compiling the Code

  • Requires Windows 2000 Server SP2 or later.

  • Requires an SMS 2003 Site Server.

See Also

Tasks

How to Create an SMS Advertisement

How to Create, Modify, and Delete SMS Objects

How to Create SMS Package and Program Objects

How to Modify an SMS Advertisement