Hello all.
Consider the following script, used for Monitoring Entry-Level Events,
from: http://www.microsoft.com/technet/scriptcenter/guide/sas_reg_teyz.mspx?mfr=true
strComputer = "."
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &
_
strComputer & "\root\default")
Set wmiSink = WScript.CreateObject("WbemScripting.SWbemSink", "SINK_")
wmiServices.ExecNotificationQueryAsync wmiSink, _
"SELECT * FROM RegistryValueChangeEvent WHERE Hive= " _
& "'HKEY_LOCAL_MACHINE' AND KeyPath= " _
& "'SOFTWARE\\Microsoft\\Windows NT\
\RegisteredOwner' AND " _
& "ValueName='CSDVersion'"
Wscript.Echo "Listening for Registry Change Events ..." & vbCrLf
Do While(1)
WScript.Sleep 1000
Loop
Sub SINK_OnObjectReady(wmiObject, wmiAsyncContext)
Wscript.Echo "Received Registry Change Event" & vbCrLf & _
"------------------------------" & vbCrLf & _
wmiObject.GetObjectText_()
End Sub
I'm trying to understand how the script works. As for the the WMI Sink
Event portion, I think I have a handle on it:
(1) You instantiate a connector and a Sink:
strComputer = "."
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &
_
strComputer & "\root\default")
Set wmiSink = WScript.CreateObject("WbemScripting.SWbemSink", "SINK_")
(2) You hook the connector to the Sink via an Asynchronous query:
wmiServices.ExecNotificationQueryAsync wmiSink, _
"SELECT * FROM RegistryValueChangeEvent WHERE Hive= " _
& "'HKEY_LOCAL_MACHINE' AND KeyPath= " _
& "'SOFTWARE\\Microsoft\\Windows NT\
\RegisteredOwner' AND " _
& "ValueName='CSDVersion'"
(3) You set up Event handlers:
Sub SINK_OnObjectReady(wmiObject, wmiAsyncContext)
Wscript.Echo "Received Registry Change Event" & vbCrLf & _
"------------------------------" & vbCrLf & _
wmiObject.GetObjectText_()
End Sub
What I can't understand exactly is the Do...Loop:
Do While(1)
WScript.Sleep 1000
Loop
What is going on in the Loop other than sleeping for 1 second?
Is the Subroutine SINK_OnObjectReady being called within the loop? If
so, how?
Any help with clarifying this would be greatly appreciated. Thanks.
- Dave