VBScript: Receiving new advertisement info from ConfigMgr 2007 via WMI Events.

Download “WMIEvent-NewAdvertisement-1.1.0.zip” WMIEvent-NewAdvertisement-1.1.0.zip – Downloaded 286 times – 2 KB

Sometimes you might need to execute code when a new advertisement is created.

This can be pretty easily obtained by using WMI events.

WMI events is supported , as far as I know, by all scripting and programming languages that supports WMI.

To setup a WMI event, you need to make a WMI Event Query. This query describes what to wait for, where to look and how often to check.

To check for new advertisements we will need to use a query simular to this one:

SELECT * FROM __InstanceCreationEvent
WHERE TargetInstance
ISA ‘SMS_Advertisement’

__InstanceCreationEvent describes  that we want the event to fire when a new instance is created. you have other options here, such as __InstanceModificationEvent.

WITHIN 10 tells the system to check every 10 seconds. this can be tuned to your needs.

last part we can modify is the type of object to look for.

ISA ‘SMS_Advertisement’ makes sure that this event fires when a SMS_Advertisement object is created. Of cause you can use this script and method for other types of objects too.

When using VBScript we are able to utilize a Swbem object called “WbemScripting.SWbemSink“. this object support and asynchronous call to vbscript events.

When the object is created, we give it a name, in this case it is “SINK_” .

We call the method ExecNotificationQueryAsync , sending the sink and the query as the input. This means that when the event fires, a sub called SINK_OnObjectReady will be called, since we named our sink “SINK_”.

In this sub we are able to catch the object that was created and use it for whatever purpose we want. In this demo we output all the content to the screen, but other ideas might be to grab the users affected and refresh their machine policy, to make sure that the advertised software will be deployed as quick as possible.

here is the source code for the script:

I hope you find this post useful, don’t hesitate to bring your feedback by email or comment.

About the Author:

Jakob Gottlieb Svendsen

Twitter: @JakobGSvendsen

Jakob Gottlieb Svendsen is a Microsoft Cloud and Data Center Management MVP (http://mvp.microsoft.com/en-us/default.aspx), Working as Global Lead Developer, Senior Consultant and Trainer at CTGlobal, where he is one of the driving forces in keeping CTGlobal a System Center Gold Partner and member of the System Center Alliance.

Since he started at Coretech in 2007, he has focused on Scripting and Development, primarily developing tools, extensions and scripts for the System Center Suite. His main area is Automation (including OMS/Azure Automation, Service Management Automation, PowerShell and Orchestrator). Another area is Windows Azure Pack / Azure Stack, where he does implementation, development, workshops and presentations. He is a world-wide renowned voice in the Automation field.

He is passionately devoted to the community, to which he contributes by being a moderator at TechNet and sharing his knowledge at https://blog.ctglobalservices.com/jgs

  • Co-founder: PowerShell User Group Denmark
  • Speaker at MMS 2016, Minneapolis (www.mmsmoa.com)
  • SCU Europe 2014, 2015, 2016 (www.systemcenteruniverse.ch)
  • Microsoft TechEd North America 2014, Houston
  • NIC 2012,2013,2014,2015, Oslo (www.nic.com)
  • Microsoft CampusDays 2011, 2013, Copenhagen
  • Microsoft TechDays 2015, Sweden (www.techdays.se)
  • Microsoft Partner Event: New in SC2012 SP1
  • User group meetings (PSUG.DK , SCUG.DK/BE/NO, AZMUG + more)
  • Microsoft Certified Trainer.
  • Microsoft Scripting Guys Forum Moderator

Main working areas:

  • Automation (Azure Automation, SMA, SCO)
  • Windows Azure Pack / Azure Stack
  • System CenterVisual Studio Team Services / Team Foundation Server
  • Development:C#.Net, VB.NET, VBScript, PowerShell, Service Manager, OpsMgr, ConfigMgr
  • Orchestrator
  • Windows Azure Pack / Azure Stack


  • Azure Automation
  • Service Management Automation
  • System Center Orchestrator
  • PowerShell, VBScript, C#.Net, VB.Net
  • Windows Azure Pack / Azure Stack Development Workshops


  1. […] Read the full post and download the script from VBScript: Receiving new advertisement info from ConfigMgr 2007 via WMI Events. […]

  2. […] Read the full post and download the script from VBScript: Receiving new advertisement info from ConfigMgr 2007 via WMI Events. […]

  3. […] October 25, 2011 in SCCM 2007, System Center Configuration Manager, Tools and Utilities by Anoop C Nair Tweet Original Post – http://blog.coretech.dk/jgs/vbscript-receiving-new-advertisement-info-from-configmgr-2007-via-wmi-ev… […]

  4. […] the full post and download the script from VBScript: Receiving new advertisement info from ConfigMgr 2007 via WMI Events. jQuery(document).ready(function($) { […]

  5. app January 30, 2014 at 2:12 - Reply

    Hi there to all, the contents present at this web page are actually amazing for people knowledge, well,
    keep up the good work fellows.

  6. These companies are experts and know how to re-establish a build
    your precious and essential property after great damages made by
    inundation or tempest. On the inside, you must document both structure and content.
    If this is done prior to any work related to water
    damage in Cincinnati, it will make the process of restoration fast and efficient.

  7. If you would like to obtain a great deal from this post then
    you have to apply such strategies to your won website.

  8. I am sure this article haas touched all the internet users, its really really goood post on building uup
    neew weblog.

  9. Jon May 16, 2014 at 10:49 - Reply

    Heya i am for the first time here. I came across this board and I in finding It really helpful
    & it helped me out a lot. I’m hoping to give one thing again and help
    others like you helped me.

    Have a look at my page: local marketing expert;

  10. Tracy May 19, 2014 at 20:53 - Reply

    An intriguing discussion is worth comment. There’s
    no doubt that that you need to write more on this subject matter, it might not
    be a taboo matter but usually folks don’t discuss such subjects.
    To the next! Best wishes!!

  11. gold ira account June 18, 2014 at 8:08 - Reply

    I know this if off topic but I’m looking into starting my own blog and was curious what all is needed to get set up?
    I’m assuming having a blog like yours would cost a pretty
    penny? I’m not very internet smart so I’m not 100% sure.
    Any suggestions or advice would be greatly appreciated.

    my weblog … gold ira account

Leave A Comment