1
有在网许多例子被展示如何订阅事件源(如RegistryValueChangeEvent
),并且响应于该事件调用一些代码。枚举WMI事件的消费者
但是,有没有办法一一列举这样的听众?例如,我想列出正在听RegistryValueChangeEvent
所有脚本或程序指标(如它们的PID)。这在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
感谢您的洞察力。在我搜索我已经看到了一些工具来查看永久订阅列表,由微软编码,并在其网站上托管。但临时订阅没有任何内容;我只能怀疑这离不开利用WMI内部(希望我是错的)来完成。 – antonone