Using Windows Task Scheduler to trigger batch on USB insertion

Get help for specific problems
Posts: 4
Joined: 8 Oct 2024

senten50

I want to trigger a batch job when a USB stick is inserted, identified by its particular Volume ID (which is visible in the FreeFileSync source drop-down).

Since Windows Task Scheduler is always running anyway, I would prefer to use it to trigger the batch, rather than take up additional Windows resources by additionally running RealTimeSync.

I am surprised how difficult it is to find step-by-step instructions to use this method in Windows Task Scheduler.

I would appreciate anyone's detailed advice on accomplishing this, including exactly where and what to enter. I am only moderately-techie not a super-techie (like a developer). Thanks.
User avatar
Posts: 4055
Joined: 11 Jun 2019

xCSxXenon

"I would appreciate anyone's detailed advice on accomplishing this, including exactly where and what to enter. I am only moderately-techie not a super-techie (like a developer)"

You should just use RTS, you're the exact reason it exists lol
Task Scheduler would have to poll the drive, which is also 'additional resources' and would be so much more difficult to get programmed and working.
Posts: 4
Joined: 8 Oct 2024

senten50

Thanks for replies ... I have related questions:

(Unfortunately, chatbot recommendations didn't help me find the Windows USB-drive-connect event that I needed in order to trigger that batch, or similar batches, which I could easily enable/disable.
I then investigated Event Viewer, while connecting and disconnecting, and looking everywhere, I couldn't see any new events when I connected/disconnected my USB drive ... I gave up.)

SO THEN ...
I used RealTimeSync and imported my batch to sync the USB flash.
It works well, and runs when I connect my drive. BUT ...
I don't know how FFS and RTS work internally. The Global XML file in apps/roaming doesn't seem to answer the following questions, and I can't find readable settings files elsewhere in the folders or a FFS/RTS entry in Task Scheduler, so:

1) DISABLING RTS BATCHES: Although the imported batch runs as expected, when I return to the RTS GUI, I don't see it listed there. Is there some setting that I cannot find, to "disable" a batch that RTS has been set to use, or must I delete the batch in the FFS GUI, or in Explorer, (or move it to another folder if I want to save it)?
If I delete or move it manually, like that:
a) Will RTS report errors (does it "know" something is missing, that should exist where it expects to find it)?
b) If I return a moved batch to its original folder, will RTS resume using it, or must I import again.
In either case, will RTS report errors?

2) MULTIPLE RTS BATCHES: Now that I can't (or shouldn't) find a way to use Windows Task Scheduler to automate FFS batches, is it possible to enable more than one batch in RTS and have it run several?
Using, FFS, I can't seem find a way to set up multiple jobs in one batch that is not cumbersome to re-edit, and organizing separate batches seems easier and safer. These are all cases where Windows Task Scheduler batches could have been manipulated easily (had I found the correct method).

Thanks, in advance.
Posts: 12
Joined: 26 Sep 2024

albinoni

Looks like you have to enable the USB event

In Event Viewer (eventvwr) under Applications and Services Logs › Microsoft › Windows › DriverFrameworks-UserMode\Operational, right-click on Operational and select Enable Log.

https://docs.nxlog.co/integrate/windows-usb-auditing.html
Posts: 4
Joined: 8 Oct 2024

senten50

To Albinoni:

Thanks, that worked!

For anyone else trying this, by enabling and looking at the event log in Event Viewer Applications and Services Logs › Microsoft › Windows › DriverFrameworks-UserMode\Operational, event# 2101 for that source seemed to be the correct one, and it was when I set up that event task in my Task Scheduler trigger and connected my USB stick. However, I don't know if that would be correct one for anyone else's system ... it may be worth trying.

Now I have all of the batch-by-batch, enable-disable control I was looking for.

By the way, moving a FFS batch out of the folder where RTS expects to find it did "disable" it ... I don't know what would happen if I moved the file back, but I'm behind now and don't have the time to experiment.

It's wonderful that the authors provided this great FFS software.
In the future I hope they will give the user in the RTS GUI much more clarity and control.
Thanks again.
Posts: 4
Joined: 8 Oct 2024

senten50

Forgot to mention ... I discovered that you can "hide" a FFS batch job in the left column ... it still remains in the folder and to "unhide" it, you "Open" that file.
However, RTS keeps using it ... that was a problem.
User avatar
Posts: 2450
Joined: 22 Aug 2012

Plerry

Trying to answer your questions on RTS above:
Describing for a Windows environment.

> 1) DISABLING RTS BATCHES:

Running RTS tasks are not shown in the RTS GUI.
Running RTS tasks are shown in the Task Manager and can be stopped from there.
If you launch RTS task manually they are also shown in your system tray and can also be stopped from there.
The same may hold for RTS tasks that are started automatically (via the Startup Folder or the Task Scheduler), depending on what caused the RTS task to start and if the RTS task runs under the logged-in user credentials.
Obviously, shutting down or restarting your computer will stop all RTS tasks (but, depending on your setup, might be started automatically again upon (re)start ).

RTS tasks can be started:
• manually, from the RTS GUI.
Disabling such RTS tasks after a (re)start: don't start the RTS task manually again.
• automatically, by placing one or more shortcuts to saved *.ffs_real RTS configurations in the users Startup folder C:\Users\[Username]\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup (or simply typing shell:startup in the address bar of File Explorer).
Disabling such RTS tasks after a (re)start: delete the shortcut to the saved *.ffs_real configuration
• automatically via the Task Scheduler (see e.g. here)
Disabling such RTS tasks after a (re)start: disable or delete the corresponding task in the Task Scheduler.

> a) errors
Some very basic errors are reported by the OS. I don't know if RTS has its own error reporting.

> b) returning a moved batch to its original folder
RTS configurations, as saved in *.ffs_real files, comprise a command line that invokes FreeFileSync (FFS) to run a specified FFF sync configuration that is (normally) saved as a *.ffs_batch file.
If you move such *.ffs_batch file, RTS will still tell FFS to open the *.ffs_batch file saved in the RTS configuration. I believe FFS will then report it can not find the *.ffs_real file (as specified in the saved RTS command line).
Obviously, if you return the *.ffs_batch file to the location specified in the RTS command line, upon the next trigger by RTS, FFS is able to open the *.ffs_batch file and run the sync.

> 2) MULTIPLE RTS BATCHES:

You can run multiple RTS instances simultaneously without any problem.
Simply create an RTS task in the RTS GUI (e.g. by dragging a saved *.ffs_batch sync configuration into the RTS GUI) and save that RTS configuration as a *.ffs_real file with a self-selected name and in a self selected location. Repeat that process for each further RTS task.
In line with what I decribed under 1), you can start your multiple RTS tasks
• manually, e.g. by double clicking all relevant *.ffs_real icons
• automatically, by placing shortcuts to all relevant *.ffs_real files in your Startup folder
• automatically, by creating a Tasks Scheduler task for each of the relevant RTS configurations