The SWbemEventSource object retrieves events from an event query in conjunction with SWbemServices.ExecNotificationQuery. You get an SWbemEventSource object if you make a call to SWbemServices.ExecNotificationQuery to make an event query. You can then use the NextEvent method to retrieve events as they arrive. This object cannot be created by the VBScript CreateObject call.
The SWbemEventSource object has these types of members:
The SWbemEventSource object has these methods.
|NextEvent||Used to retrieve an event in conjunction with SWbemServices.ExecNotificationQuery.
The SWbemEventSource object has these properties.
||Used to read or change the security settings.
This script uses the methods of the SWbemEventSource class and the SWbemServices class in conjunction with a WQL query for application events. For more information about WMI event notification and queries see Monitoring Events, Running a Script Based on an Event, and Receiving Asynchronous Event Notifications.
' Connect to WMI, obtaining an SWbemServices object set svc = CreateObject("Wbemscripting.SWbemLocator")._ ConnectServer(,"root\cimv2") ' Obtain an SWbemEventSource object from the ' SWbemServices.ExecNotificationQuery method to specify the ' event source as "Application" events in a Win32_NTLogEvent set evtsrc = svc.ExecNotificationQuery("SELECT * " _ & "FROM __InstanceCreationEvent " _ & "WHERE TargetInstance ISA 'Win32_NTLogEvent'" _ & "AND TargetInstance.Logfile ='Application'") ' Wait for an event by executing the NextEvent method on the ' SWbemEventSource object. while (num < 5) set inst = evtsrc.NextEvent(-1) Wscript.echo inst.TargetInstance.Logfile num = num + 1 wend
|Minimum supported client
|Minimum supported server
||Windows Server 2008