The following example demonstrates how to modify an SMS advertisement object (SMS_Advertisement) so that it either runs at the times it is assigned to run or ignores those times. Either way, because it is assigned, users do not see it unless you select the Allow users to run the program independently of assignments property on the advertisement. The advertisement now runs only after the assigned times and when the assignments are enabled.
This script can be useful if you have an advertisement that you want to force to run at night but do not want users to run during the day. For example, you could create the advertisement with an assignment to run after 7:00 P.M. on the first day and then create a scheduled task to run this script every evening at 7:00 P.M. and to run it again at 5:00 A.M.
|When using this script with Task Scheduler, you can remove or comment the WScript.Echo lines.
Dim objAdvertisment Set objAdvertisment = GetObject( "WinMgmts:root\SMS\site_999:SMS_Advertisement.AdvertisementID='99920000'") WScript.Echo "Advertisement: " & objAdvertisment.AdvertisementName WScript.Echo "Assigned Schedule Enabled?: " & objAdvertisment.AssignedScheduleEnabled If objAdvertisment.AssignedScheduleEnabled=True Then WScript.Echo "Was Enabled" objAdvertisment.AssignedScheduleEnabled=False objAdvertisment.Put_ WScript.Echo "Now Disabled" Else WScript.Echo "Was Disabled" objAdvertisment.AssignedScheduleEnabled=True objAdvertisment.Put_ WScript.Echo "Now Enabled" End If
Compiling the Code
- Requires Windows 2000 Server SP2 or later.
- Requires an SMS 2003 Site Server.