Share via


Creating the Advertisement

SMS evaluates advertisements to determine which clients receive a specific program. Using the SMS_Advertisement class, you specify:

  • The package and program to run on the client.
  • The target collection of computers, users, or user groups that will receive the program.
  • Optionally, a schedule of when the program is available to clients.

SMS propogates advertisements to child sites. Each site offers the advertisements to clients based on the collection that the advertisement has specified. Because collection membership can change, collections are evaluated at regular intervals. If the membership of a collection changes (members have been added or removed), the offering of the associated advertisements also change to reflect the membership changes (advertisements are offered to new members or revoked from those who were removed from the collection). Collections that contains one or more query-based membership rules are useful as a guarantee that the program is directed to all clients that meet the criteria.

However, query-based collections are not appropriate for situations that require a greater degree of control. For example, if you have a limited number of licenses for a particular software application, you would not want to use query-based collections to distribute that software. Instead, you should use a fixed collection, based on direct rules, for the advertisement destination. This approach is often more appropriate for distributing to computers where the destination collection is relatively static and well defined.

The following example shows how to create an advertisement. This example continues the example started in Creating a Package and Programs Using SMS Classes.

[C/C++]
This example assumes the IWbemServices and IWbemContext (context qualifiers) objects have been created. For information on connecting to SMS, see Connecting to the SMS Namespace. For information on creating a context object, see SMS Context Qualifiers.

  [C/C++]
    IWbemClassObject    *pclsAdvert = NULL;    //SMS_Advertisement class
    IWbemClassObject    *pinstAdvert = NULL;   //and instance
    _variant_t           vTemp = NULL;


    hr = pServices->GetObject(_bstr_t(L"sms_advertisement"), 0, NULL,
                              &pclsAdvert, 0);
    hr = pclsAdvert->SpawnInstance(0, &pinstAdvert);
    pclsAdvert->Release();

    //Creates a mandatory advertisement that runs at user logon.
    vTemp = (long)33554944;     //ONUSERLOGON(bit 9), NO_DISPLAY(bit 25)
    hr = pinstAdvert->Put(L"AdvertFlags", 0, &vTemp, NULL);

    vTemp = "Daily Status Check";
    hr = pinstAdvert->Put(L"AdvertisementName", 0, &vTemp, NULL);

    //Create an arrary of schedule token objects derived from SMS_ScheduleToken.
    //This example uses SMS_ST_RecurInterval to create a daily schedule
    //for the advertisement. If you didn't create a schedule, the ad would run
    //only one time. The SafeArray variables and the schedule objects are defined
    //in the package example.
    saBounds.cElements = 1;
    saBounds.lLbound = 0;
    psaTokens = SafeArrayCreate(VT_UNKNOWN, 1, &saBounds);

    hr = pServices->GetObject(_bstr_t(L"SMS_ST_RecurInterval"), 0, NULL,
                              &pclsSchedule, 0);
    hr = pclsSchedule->SpawnInstance(0, &pinstSchedule);
    pclsSchedule->Release();

    vTemp = (long)1;
    hr = pinstSchedule->Put(L"DaySpan", 0, &vTemp, NULL);

    vTemp = "20000314050000.000000+***";
    hr = pinstSchedule->Put(L"StartTime", 0, &vTemp, NULL);

    pinstSchedule->QueryInterface(IID_IUnknown, (void **)&pUnknown);
    SafeArrayPutElement(psaTokens, &lArrayIdx, pUnknown);
    pUnknown->Release();
    pinstSchedule->Release();

    vTemp.vt = VT_ARRAY | VT_UNKNOWN;
    vTemp.parray = psaTokens;
    hr = pinstAdvert->Put(L"AssignedSchedule", 0, &vTemp, NULL);
    SafeArrayDestroy(psaTokens);

    vTemp = true;
    hr = pinstAdvert->Put(L"AssignedScheduleEnabled", 0, &vTemp, NULL);

    vTemp = "SMS00002";    //All Users
    hr = pinstAdvert->Put(L"CollectionID", 0, &vTemp, NULL);

    vTemp = "Run StatusCheck every day at logon";
    hr = pinstAdvert->Put(L"Comment", 0, &vTemp, NULL);

    vTemp = true;
    hr = pinstAdvert->Put(L"IncludeSubCollection", 0, &vTemp, NULL);

    vTemp = bstrPackageID;
    hr = pinstAdvert->Put(L"PackageID", 0, &vTemp, NULL);
    SysFreeString(bstrPackageID);

    vTemp = "20000315060000.000000+***";
    hr = pinstAdvert->Put(L"PresentTime", 0, &vTemp, NULL);

    vTemp = "Check Status";
    hr = pinstAdvert->Put(L"ProgramName", 0, &vTemp, NULL);

    hr = pServices->PutInstance(pinstAdvert, 0, pSMSContext, NULL);
    pinstAdvert->Release();

[Visual Basic]
This example assumes the SWbemServices and SWbemNamedValueSet (context qualifiers) objects have been created. For information on connecting to SMS, see Connecting to the SMS Namespace. For information on creating a context object, see SMS Context Qualifiers.

  [Visual Basic]
    Dim instAdvert As SWbemObject

    Set instAdvert = Services.Get("SMS_Advertisement").SpawnInstance_

    'Creates a mandatory advertisement that cannot be run independently.
    instAdvert.AdvertFlags = 33554464     'IMMEDIATE(5)  NO_DISPLAY(25)
    instAdvert.AdvertisementName = "Office 2000 Installation"
    instAdvert.CollectionID = "SMS00002"      'All Users
    instAdvert.IncludeSubCollection = True

    'Associates the package with an advertisement.
    instAdvert.PackageID = PackageID

    'When to present the offer.
    instAdvert.PresentTime = "20000309123000.000000+***"
    instAdvert.PresentTimeEnabled = True

    'Associates the program with an advertisement.
    instAdvert.ProgramName = "Office 2000 Setup"

    'Create the advertisement.
    instAdvert.Put_ , SMSContext