网上有很多示例演示如何订阅事件源(如RegistryValueChangeEvent
),并调用一些代码来响应该事件。
但是有没有办法枚举这样的听众?例如,我想列出所有正在收听RegistryValueChangeEvent
. 这在 WMI 中可能吗?
这是一个示例脚本文件,监听注册表更改事件,我想检测:
strComputer = "."
Set objWMIServices=GetObject( _
"winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default")
set objSink = WScript.CreateObject( _
"WbemScripting.SWbemSink","SINK_")
objWMIServices.ExecNotificationQueryAsync objSink, _
"Select * from RegistryValueChangeEvent Where " & _
"Hive = 'HKEY_LOCAL_MACHINE' and " & _
"KeyPath = 'SYSTEM\\ControlSet001\\Control' and " & _
"ValueName = 'CurrentUser'"
WScript.Echo "Listening for Registry " _
& "Change Events..." & vbCrLf
While(True)
WScript.Sleep 1000
Wend
Sub SINK_OnObjectReady(wmiObject, wmiAsyncContext)
WScript.Echo "Received Registry Value Change Event" _
& vbCrLf & wmiObject.GetObjectText_()
End Sub