Windows – How to prevent a scheduled task from running if the same task is already running

scheduled-taskschedulingscriptingwindowswindows-xp

I have written a php script to check if there are any new files in a folder and, if any new files exist, upload them to a server. These files can be quite large. I want to run this script frequently-let's say every 5 min-as a scheduled task so that the files get moved to the server as soon as possible. However, once the script is already attempting to upload a file, I do not want it to be run again, as I am afraid the second instance will overwrite the file that is already being uploaded to the server.

How can I run the script as a scheduled task unless the script is already running?

Best Answer

Assuming you're just setting the task to "Repeat" in the XP "Scheduled Tasks" system, no further action on your part is needed. Scheduled Tasks won't "Repeat" a task if it's already running.

If you want to override that default, you can check the box "If the task is still running, stop it at this time" to cause the task scheduler to kill the last instance before starting a new one (though it sounds like you probably don't want that).