- Hive = "HKEY_LOCAL_MACHINE"
- KeyPath = "Software\333"
- ValueName = "444"
-
- On Error Resume Next
- Set ws = CreateObject("WScript.Shell")
- SINK_OnObjectReady 0, 0
- Set Sink = WScript.CreateObject("WbemScripting.SWbemSink", "SINK_")
- Set objWMIServices = GetObject("winmgmts:" & _
- "{impersonationLevel=impersonate}!\\.\root\default")
- objWMIServices.ExecNotificationQueryAsync Sink, _
- "Select * from RegistryValueChangeEvent Where " & _
- "Hive = '"&Hive&"' and " & _
- "KeyPath = '"&Replace(KeyPath,"\","\\")&"' and " & _
- "ValueName = '"&ValueName&"'"
- WScript.Echo "Listening for Registry Change Events..." & vbCrLf
- Do : WScript.Sleep 1000 : Loop
-
- Sub SINK_OnObjectReady(wmiObject, wmiAsyncContext)
- Value = ws.RegRead(Hive&"\"&KeyPath&"\"&ValueName)
- 'WScript.Echo Value
- if CStr(Value)="29" then
- ws.Popup "注册表值变成了29", 3, "通知"
- ws.RegWrite Hive&"\"&KeyPath&"\"&ValueName, 20, "REG_DWORD"
- end if
- End Sub
复制代码
|