The processes by which SMS objects are managed can be divided into the following categories: 

For more information on creating and deleting WMI objects, see the WMI SDK.

To create an SMS object

  1. Connect to an SMS Provider, and get the SWbemServices object.

  2. Create an instance of an SMS object by using the SpawnInstance method supported by the desired class. For example, to create an instance of a package object (SMS_Package), use the following code:

    Set objNewPackage = objSWbemServices.Get("SMS_Package").SpawnInstance_()
    
  3. Populate the required properties. For example, the following code sets the properties for a package:

    objNewPackage.Name = "Package Name"
    objNewPackage.Description = "A new package"
    objNewPackage.PkgSourceFlag = 2
    objNewPackage.PkgSourcePath = "C:\temp"
    
  4. Save the SMS object by using the Put_ method supported by the SMS object class. For example, the following line of code puts or saves a package:

    objNewPackage.Put_
    

To modify an SMS object

  1. Get the instance of the required SMS object by using the Windows Script Host GetObject method and supplying the path to the required object. For example, to get an instance of an advertisement object (SMS_Advertisement) identified as 99920002, use the following code.

    Set objAdvertisement = GetObject( "WinMgmts:root\SMS\site_999:SMS_Advertisement.AdvertisementID='99920002'")
    
  2. Set the required properties of the SMS object. To enable the assigned schedule for an advertisement object, set the AssignedScheduledEnabled property to True, as in the following example:

    objAdvertisement.AssignedScheduleEnabled=True
    
  3. Update the SMS object by using the SMS object class Put method. For example, to update the advertisement opened in step 1, use the following code:

    objAdvertisement.Put_
    

To delete an SMS object

  1. Get the instance of the required SMS object by using GetObject and supplying the path to the required object. For example, to get an instance of an advertisement object (SMS_Advertisement) identified as 99920003, use the following code:

    Set objAdvertisement = GetObject( "WinMgmts:root\SMS\site_999:SMS_Advertisement.AdvertisementID='99920003'")
    
  2. Delete the SMS object instance by using the SMS object class Delete_ method. For example, to delete the advertisement object opened in step 1, use the following code:

    objAdvertisement.Delete_ 
    

See Also