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:

Share:
15,992
Dustin
Author by

Dustin

Updated on June 11, 2022

Comments

  • Dustin
    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
    GravityWell over 10 years
    Unless 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
    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