Windows: File Monitoring Script (Batch/VBS)
15,992
In VBScript, you can monitor a folder for file changes by subscribing to the WMI __InstanceModificationEvent
event. These articles contain sample code that you can learn from and adapt to your specific needs:
- WMI and File System Monitoring
- How Can I Monitor for Different Types of Events With Just One Script?
Author by
Dustin
Updated on June 11, 2022Comments
-
Dustin almost 2 years
I'm currently in working on a script to create a custom backup script, the only piece I'm missing is a file monitor. I need some form of a script that will monitor a folder for file changes, and then run a command with the file that's changed.
So, for example, if the file changes, it'll execute "c:/syncbatch.bat %Location_Of_File%"
-
GravityWell over 10 yearsUnless deliberately disabled, WMI is running on every Windows system I've used since XP. So not sure how that is more bloated than a 3rd party .Net app?
-
vvolkgang almost 10 years@GraviWell it's portable, small and can terminate on cue, at least for me The Folder Spy is a far better solution for this problem. On another note, it's great it has an SDK, which will be useful for another thing I have in mind so, double thumbs up to the AP