SWbemEventSource对象从事件查询结合SWbemServices.ExecNotificationQuery检索事件。如果您致电SWbemServicesExecNotificationQuery进行事件查询,则会得到SWbemEventSource对象。然后,您可以使用NextEvent方法在事件到达时检索事件。此对象不能由VBScript CreateObject调用创建。
方法
SWbemEventSource对象定义了以下方法。
方法 |
描述 |
NextEvent |
用于与SWbemServices结合ExecNotificationQuery检索事件。 |
属性
SWbemEventSource对象定义了以下属性。
属性 |
描述 |
安全_ |
用于读取或更改安全设置。 |
示例代码[Script]
此脚本使用SWbemEventSource类和SWbemServices类的方法与应用程序事件的WQL查询结合使用。有关WMI事件通知和查询的详细信息,请参阅监控事件,基于事件运行脚本和接收异步事件通知.
'连接到WMI,获取一个SWbemServices对象
设置svc =
CreateObject("Wbemscripting.SWbemLocator")._
ConnectServer(,"root\cimv2")
'从中获取一个SWbemEventSource对象
'SWbemServices.ExecNotificationQuery方法指定
'事件源为Win32_NTLogEvent中的“应用程序”事件
设置evtsrc = svc.ExecNotificationQuery(“SELECT *”_
&“FROM __InstanceCreationEvent”_
&“WHERE TargetInstance ISA'Win32_NTLogEvent'”_
&“AND TargetInstance.Logfile ='Application'”)
'通过执行NextEvent方法来等待事件
'SWbemEventSource对象。
while(num <5)
set inst = evtsrc.NextEvent(-1)
Wscript.echo inst.TargetInstance.Logfile
A = A + 1
WEND
要求
客户 |
需要Windows Vista,Windows XP,Windows 2000 Professional,Windows NT Workstation 4.0 SP4及更高版本,Windows Me,Windows 98或Windows 95 OSR2及更高版本。 |
服务器 |
需要Windows Server 2008,Windows Server 2003,Windows 2000 Server或Windows NT Server 4.0 SP4及更高版本。 |
类型库 |
使用Wbemdisp.tlb。 |
DLL |
需要Wbemdisp.dll。 |