3

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?

  • @1Fish_2Fish_RedFish_BlueFish It's a deprecated backup program called VersionBackup. Basically it runs with a window that displays progress and at the end of the run pops up a window if there were any problems. Unfortunately it has no documented command line options. On Windows 7 it had some built-in way to only run itself once a day but since upgrading to Windows 10 this no longer works. So if it runs a second time, it repeats the backup process. – Jim Feb 1 '16 at 22:24
  • Well then you may be able to just create a simple batch script, put some logic in it to first check for a "check" file that may be called something like VersionBackup_20160201.txt and if it does NOT exist, create it, and then run the app. If it DOES exist, then DO NOT run the VersionBackup.exe and exit. This way you ensure per day e.g. <YYYYMMDD> that it only runs once and creates that file just before it runs. If you're intested, I have an example script logic I'll add as an answer if you think it'd potentially be a solution you could use or at least test with perhaps? – Pimp Juice IT Feb 1 '16 at 23:51
  • Also in addition to my above comments, can you tell me if this is the site and software you use, and which configuration you use if so (e.g. the client and server, the master, etc.)? sb-aw.com/download.html – Pimp Juice IT Feb 1 '16 at 23:54
  • @1Fish_2Fish_RedFish_BlueFish Thanks, that would be useful. The site you found is correct, I am using the "master" version, which is their non-enterprise, consumer tool. – Jim Feb 2 '16 at 7:23
1

Run a task once a day at log on

I am trying to set up a schedule task to run an exe exactly once a day.

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.

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 the YYYYMMDD 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 the YYYYMMDD part of it's file name each day.

    • Just change the C:\Path or plug in the UNC path to where that needs to point to in your environment
  • The 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 of C:\Path\VersionBackup_20130202.txt for today as in my example.

    • This will essentially check if the file exists for today, if so, end the script, if it does not exist, create it and then run the VersionBackup.exe of whatever it's EXE name is called. This way this thing could be scheduled with Task Scheduler to once once an hour pointing to the batch script and per the batch script logic, it'll only be allowed to run once per day.
  • 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

@ECHO ON

:::: SET YYYYMMDD format for date
FOR /F "TOKENS=2-4 DELIMS=/ " %%A IN ("%DATE%") DO SET "DT=%%C%%B%%A"

:SetCheckFile
SET CheckDir=C:\Path
SET checkfile=%CheckDir%\VersionBackup_%DT%.txt
IF NOT EXIST "%CheckDir%" MD "%CheckDir%"
IF EXIST "%checkfile%" GOTO EOF
ECHO Creating the check file for date %DT% to ensure only one Version Backup run for the day>>"%checkfile%"

:StartApp
START "" "C:\Path\VersionBackup.exe"
GOTO EOF

  • Thanks, this works! I did notice on my system that %DATE% evaluates to 2016/02/02, so I changes the for loop to FOR /F "TOKENS=1-3 DELIMS=/ " %%A IN ("%DATE%") DO SET "DT=%%A%%B%%C" – Jim Feb 2 '16 at 11:33
0

Drop the .exe in one of the following folders to run it when the computer boots up. You won't have to do anything in Task Scheduler.

For just the current user:

C:\Users\username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

For all users:

C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup

Hope this helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.