Windows (10) Task Scheduler trigger on folder changes

Rafael Facanha 21 Reputation points
2022-06-06T13:49:04.14+00:00

Hi Experts,

I have a .exe file which I wanted to run every time a new file is created in a specific folder but I don't figure out how to trigger this event.
Is there any way to do it with Task Scheduler?
Thanks!

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
11,977 questions
{count} votes

Accepted answer
  1. Michael Taylor 56,271 Reputation points
    2022-06-06T14:55:54.81+00:00

    Scheduled tasks cannot be triggered based upon file system changes. The event-based trigger that is supported is really for listening to events in the event log. I guess you could have file system events logged and then build a trigger from that but it would be inefficient and a resource hog.

    The correct approach is to use FileSystemWatcher. You can configure the watcher to alert you when file system events occur. You can then do whatever you need to. For this to work you'd need to build an app that hosts the watcher and responds to events. You would then need to ensure the app is running. This might be where you would use the scheduler to have the program run at logon (or startup). Then as long as the app is running you would receive notifications.

    Note that file system events happen as part of the IO so you need to build your watcher program multi threaded and have it defer the actual work (starting your other app or doing whatever functionality it is already doing) to a separate thread. If you don't do this then you will slow down IO and potentially cause the buffer to overflow which means you'll miss events. You should refer to the many articles online on how to properly build a file system watching program. The issues and guidance are well documented.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.