A Windows Service (built with .NET) that watches one or more directories for filesystem changes and runs a specified PowerShell or batch script for each watcher.
Useful for automating log processing, file ingestion, sync tasks, or any time you want scripts triggered by filesystem events.
- Watch multiple directories configured in a YAML file
- Per-watcher toggle for IncludeSubdirectories
- Runs PowerShell (.ps1) or Batch/EXE scripts
- Global debouncing (one run per script after a configurable delay) to avoid bursts firing many runs
- Simple installation via
Install.bat/Uninstall.bat
debounceDelaySeconds: 120
watchers:
- path: >
C:\Users\pkste\Documents\Notes
includeSubdirectories: true
scriptPath: >
C:\Users\pkste\Documents\Scripts\Test.bat
- path: >
C:\Watched\Reports
includeSubdirectories: false
scriptPath: >
C:\Scripts\process-reports.bat
- path: >
D:\Data\Uploads
includeSubdirectories: true
scriptPath: >
C:\Scripts\process-uploads.ps1Fields
debounceDelaySeconds— global delay (in seconds) used for debouncing all watchers.path— directory to monitor.includeSubdirectories—true/falsewhether to watch subfolders.scriptPath— absolute path to the script or executable to run when events are debounced.
- Ensure .NET SDK (version used for the project) is installed.
- From the project root:
dotnet build- The service executable will be under
.\bin\Debug\net9.0\(ornetX.Ydepending on project target).
Run the Install.bat as Administrator. The repository includes an Install.bat which contains the following commands:
copy .\config.yaml .\bin\Debug\net9.0\config.yaml
sc create RunScriptOnFilesystemChanges binPath= "~\source\RunScriptOnFilesystemChanges\RunScriptOnFilesystemChanges\bin\Debug\net9.0\RunScriptOnFilesystemChanges.exe"
sc start RunScriptOnFilesystemChangesWhat it does:
- Copies
config.yamlinto the output folder where the service executable runs. - Creates a Windows service named
RunScriptOnFilesystemChanges. - Starts the service.
Important
- You must run the
Install.batas Administrator. - Update the
copyandsc createpaths if your build output is in a different folder or you publish the app to another location. sc create'sbinPathshould point to the built.exe. If the path contains spaces, ensure proper quoting.
Run the Uninstall.bat as Administrator. The repository includes an Uninstall.bat which contains the following commands:
sc stop RunScriptOnFilesystemChanges
sc delete RunScriptOnFilesystemChangesWhat it does:
- Stops the service.
- Deletes the service registration.
-
The service uses .NET logging. By default, logs will appear in the Windows Event Log under Application (check Event Viewer → Windows Logs → Application).
-
If scripts fail, the service logs standard output and standard error from the scripts.
-
Check the following if something doesn't run:
- The service account has permission to access the watched directory and to execute the script.
- The
scriptPathis correct and executable. - PowerShell scripts are executed with
-ExecutionPolicy Bypassby the service. - If you change
config.yaml, restart the service to pick up changes.
- Always test your scripts manually before relying on the service to invoke them.
- If you need to deploy to production, consider publishing the service with
dotnet publishand updatingInstall.batto copy the published output. - Avoid long-running blocking operations inside the scripts that could overlap — if overlap is a concern, add locking inside your script or add logic in the service to check for running instances (not included by default).
- Use absolute paths in
config.yaml.
GPL-3.0