Редактиране

Споделяне чрез


SWbemEventSource object

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.

Members

The SWbemEventSource object has these types of members:

Methods

The SWbemEventSource object has these methods.

Method Description
NextEvent Used to retrieve an event in conjunction with SWbemServices.ExecNotificationQuery.

Properties

The SWbemEventSource object has these properties.

Property Access type Description
Security_
Read-only
Used to read or change the security settings.

Examples

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

Requirements

Requirement Value
Minimum supported client
Windows Vista
Minimum supported server
Windows Server 2008
Header
Wbemdisp.h
Type library
Wbemdisp.tlb
DLL
Wbemdisp.dll
CLSID
CLSID_SWbemEventSource
IID
IID_ISWbemEventSource

See also

Scripting API Objects