I am trying to set up a schedule task to run an exe exactly once a day. I have tried the following:
Trigger daily 4:00AM, "run task as soon as possible after a scheduled start is missed"
This approach works perfectly if I don't have a password set on my account, in which case Windows boots directly to the Desktop – after a short delay, the task runs.
When I added a password to my account, the task no longer ran. In the task history I see warnings being logged:
Task Scheduler did not launch task "X" because user "Y" was not logged on when the launching conditions were met. User Action: Ensure user is logged on or change the task definition to allow launching when user is logged off.
This seems like a stupid warning – under the "Security options" I have "Run only when user is logged on" selected. Why is Task Scheduler trying to launch the task before the user logs on?
Trigger daily 4:00AM and "at log on", run as soon as possible
This approach did not have the effect I intended, i.e. I wanted both conditions to be true, i.e. if "after 4:00AM daily" is true and "log on" is true, then run the task; and for each successive "log on" event that day, the "after 4:00AM daily" won't be true so it'll wait for the next day. This is unfortunately not how Task Scheduler works, and with this approach, the task runs after every log on.
Run whether user is logged on or not
I cannot use this approach because the exe I'm trying to run sometimes requires user input when it is complete. In general, there are a variety of reasons one might not be able to use this option.
Other options
In the realm of desperate workarounds, I am considering writing a batch script that will write out to a file and be able to detect if it's been called before.
Surely there must be a better way to achieve this seemingly common and simple scheduling use case?
Best Answer
Okay, so the below is an example with very basic and simple batch script logic as you stated in the comment may be useful in your case per issues you're facing.
I also will reference another post (at the bottom of this answer) on Task Scheduler with gotcha's, etc. just in case you have further issues with Task Scheduler not working as expected when executing the batch script. Even though the options you pick specifically in the configuration may be different as well as the OS, the gotcha's at this level are likely the same still so take a quick look at that post too if you have trouble with the batch scheduling with Task Scheduler not working as expected.
Basic Script Breakdown
The
FOR /F
loop creates theYYYYMMDD
variable to use for the current date.The
CheckDir
is a local drive path or even a UNC path of\\servername\sharename\folder
that you will put this small check file with theYYYYMMDD
part of it's file name each day.C:\Path
or plug in the UNC path to where that needs to point to in your environmentThe
checkfile
is ONLY the name of the file with the%CheckDir%\
in front of it and the%DT%
appended to the end of it before the .txt extension. It'll for example give you a final result ofC:\Path\VersionBackup_20130202.txt
for today as in my example.The
START "" "C:\Path\VersionBackup.exe"
just needs to point to full path where the EXE name exist that does the version backup operation.Batch Script Example