Google "VBS monitor Registry", Top 5 is the same code, I checked, the source is Hey, scripting guy! Blog on an article called "How Can I Monitor Changes to a Registry Key" articles, really shameless.
Article I have no time to translate, paste the code:
Copy Code code as follows:
StrComputer = "."
Set objWMIService = GetObject ("winmgmts:\\" & StrComputer & "\root\default")
Set Colevents = Objwmiservice.execnotificationquery _
("SELECT * from RegistryKeyChangeEvent WHERE hive= ' HKEY_LOCAL_MACHINE ' and" & _
"Keypath= ' Software\\microsoft\\windows\\currentversion\\run '")
Todo
Set objlatestevent = colevents.nextevent
WScript.Echo Now & ": The registry has been modified."
Loop in fact, there are 4 classes in WMI that can monitor the registry, respectively
- registryevent
- registrytreechangeevent
- registrykeychangeevent
- registryvaluechangeevent
See the class name to know what is to do, the above code used is registrykeychangeevent, that is, registry keys to change events.
I don't want to talk about the use of WMI events here, it's a very basic thing, and I don't want to translate reference documents, and if I don't understand this simple English, I don't need to use WMI. I think the hardest part about WMI is that there are too many classes inside, and many times you don't know which class to use to implement the desired functionality. And now, which class is already very clear, this article can also be concluded.
Reference Links: registering for System Registry Events
Original: http://demon.tw/programming/vbs-wmi-monitor-changes-to-a-registry-key.html