Windows 10 scheduled task not running - windows

I have a very simple bat file which does a MysqlDump.
When I manually execute the bat file, it works. When I click "execute" in my scheduled taks, it works. But the scheduled task itself, doesn't run when it should run (timer expires).
I've setup a scheduled task to run every 5 minutes. In the scheduled taks manager I can see "next time to execute" "16:55". But when it is 16:55 the text updates to "next time to execute" "17:00". But in the "previous time executed" nothing changes. It still shows the time I manually have executed the task.
So, the weird thing is, when I click "execute" for the task, it runs. But when the time expires and it should run by itself, nothing happend.
I've enabled the history for the task. But even there nothing happens.
Can you help?

Related

Windows Task Scheduler - Run task nonstop

I have a task/script, that I need to run nonstop.
However, I have set up the task, and I keep trying to run it. It does run, but after I refresh the tasks, it stops, says "Ready," and also says "Task Completed."
The thing is, I was able to do this before, and it continued running.
My question is, how can I make Task Scheduler continue to run nonstop? Any help would be appreciated.
The Task-Scheduler can not automatically wait on every derived process / application beeing executed. Once the main handle "finishes", the task is considered completed, and it's status turns to ready, even if there is still stuff running in the Background.
Example:
Consider two tasks, with the following actions:
Program cmd.exe, Parameters: /c pause
Program cmd.exe, Parameters: /c "start cmd.exe /c pause"
In case 1, the taskscheduler will say "running", until the cmd window closes. (Which is what you are asking for?) Case 2 invokes an action from within the first cmd window. So, even if the SECOND cmd-window remains open, the process created by the taskscheduler itself terminates - hence it considers the execution completed and switches back to "ready".
So: Make sure, your main-process started by the task scheduler (and maybe invoking other processes) does not end, before all the work is done.
in the above example, this could be achived like
Program cmd.exe, Parameters: /c "start /wait cmd.exe /c pause"
window 2 will be "paused" and window 1 waits for window 2 to close, leaving that process in an active state. So, the task scheduler keeps displaying "running".
to provide a less generic answer, you should update your question with more information: What task are you executing? What kind of script is it? What are you task settings, and what is your expected behaviour?

Task scheduler is not executing Batch call to VBS script but it works fine when executed manually

We are running a Batch script call "C:\My Scripts\Script.vbs" which when run manually, executes the vbscript perfectly. However when setting up a scheduled task, it works some times, but most times it never completes and we have set the task to forcibly stop after 4 hours - which does not seem to work either. The task is set to run with administrator privileges and we can see in the task history that the task is running when it is set to run but it does not seem to ever execute the script properly. Any recommendations and help you can provide are much appreciated.
Update: It will run when set to run when user is logged on but will not run when set to run where user is logged on or not

Command Prompt doesn't close after scheduled task runs

I have a job scheduled to run at 9:30 every day using Windows task scheduler. The problem is after it runs, the command prompt stays open. Does anyone know how to get it to close?
The full text in the "Add arguments (optional):" field is:
C:\WinPython64bit\notebooks\TreasuryTest.py exit 0
I have searched all over, but most fixes are for use directly in the command prompt, and it seems to function differently from the task scheduler.

running shell script with windows task scheduler

I currenty have a simple shell script that I created for a linux machine to be run using cron, but now I want to be able to run the file using windows task scheduler. I have tried to get it to work using cron for cygwin, but even after running cron-config successfully and ensuring that the shell script can be executed successfully, for some reason the cron task simply wasn't executing. So I decided to give in and use the windows task scheduler. In order to do this, I looked at the following posts about the issue:
Cgywin .sh file run as Windows Task Scheduler
http://www.davidjnice.com/cygwin_scheduled_tasks.html
in my case, the entry in the "actions" tab of the new task looks like this:
program/script: c:\cygwin64\bin\bash.exe
arguments: -l -c "/cygdrive/c/users/paul/bitcoinbot/download_all_data.sh >> cygdrive/c/users/paul/bitcoinbot/logfile.log 2>&1"
start in: c:\cygwin64\bin
Notice that I redirected the output of the shell script to a log file, so that I should be able to see there whether the program run. Other than that, I simply edited the "trigger" tab to run the task daily, and set the time to a couple of minutes in the fture to see whether it ran successfully.
Alas, when I look at the detailed event history for the task, nothing changes when the trigger time passes. And when I manually "run" the task, the event history seems to add a few different events, but the task is completed within seconds, whereas this task should take over an hour (and it does when the shell script is executed directly from the terminal). And when I look for the log file that should have been created, there is nothing.
Does anyone have any idea what might be the issue here? How can I get my task to run properly at the trigger time, and how can I make sure it does so?
Best,
Paul
EDIT:
here are the pictures showing event history, as per Ken White's request.
Please ignore the fact that it says there are 24 events. These are from multiple separate runs of the task. The events shown here are a complete list of the events triggered by a single run.
EDIT 2:
Regarding my attempts to get cron to work, I have run into the following problem when I try to start the cron service using cygrunsrv. First of all, I tried to start cron by typing
cygrunsrv -I cron -p /usr/sbin/cron.exe -a -D
Now when I type
$cygrunsrv -Q cron
Service: cron
Current State: stopped
Command: /usr/bin/cron.exe
Now, I tried to start the cron service by typing
cygrunsrv -S cron
Cygrunsrv: Error starting a service: QueryServiceStatus: Win32 error 1062:
The service has not been started.
Does anyone hae any idea what this error means? I tried googling it, but couldn't find any answers.

How does Windows Task Scheduler in Win7 recognize a failed task?

I am working with Windows 7 and I have an application that returns zero (0x0) when successful and one (0x1) on error situations.
I have scheduled this app using Windows Task Scheduler. I have checked the option boxes "If the task fails, restart every" and "Attempt to restart up to:".
I thought that a non-zero return code from the app would be enough to trigger the task to be restarted after the given interval. But nothing happens.
Any ideas what could be the issue? I tried to google it but did not found anything relevant.
Create a new task and set the custom event query like this:
<QueryList>
<Query Id="0" Path="Microsoft-Windows-TaskScheduler/Operational">
<Select Path="Microsoft-Windows-TaskScheduler/Operational">*[System[EventID=201]] and *[EventData[Data[#Name='ResultCode']!='0']] and *[EventData[Data[#Name='TaskName']='\YOUR TASK NAME HERE']]</Select>
</Query>
</QueryList>
Set the trigger advanced settings to Delay the task for a period of time like 15 minutes.
Configure the action of the new task to start a program:
Program/script:
schtasks
Add arguments:
/Run /TN "\YOUR TASK NAME HERE"
This will schedule the original task to run again 15 minutes after a non-zero result code is logged in the event.
I've experienced the same problem on a Windows 2008 server Windows Task Scheduler.
The action return a non zero code but the scheduler consider the task completed:
Task Scheduler successfully completed task "\SET Tasks\Scheduled task [Backup SET Server]" , instance "{...}" , action "C:\Windows\SYSTEM32\cmd.exe" with return code 1.
I've found on the web only one answer:
The Windows Task Scheduler does not
examine the exit code or any other
values when your task completes. You
must handle any error processing
within your own script or program.
...in this document: www.onlinetoolworks.com/docs/winTaskSched.doc
So I think now that the only way to workaround this problem may be to use task triggering on event. I'm investigating.
Regards,
Olivier.
You can,
activate history for Schedule (if not already)
on a History "Action completed" right click "Attached Task to This Event..."
Set a custom filter like this:
*[System[(EventID=201)]] and *[EventData[Data[#Name='ResultCode']='1']]
Enjoy
Tilo
used on Win 2008 R2 (Exchange as email server)
Nobody has answered the title question though. It seems as though the task scheduler has no way to detect a failed task? Surely it must have something because it has an option to restart failed tasks!
The option "If the task fails, restart" is misleading, a failed task is when Task Scheduler is not able to run one of the action correctly, not when the script itself runs and return an error code.
A very clever workaround suggested here can be used instead of additional task querying for events:
The issue is the actions are only considered to fail if they cannot be started. This is pretty dumb, but the scheduler doesn't care about the results of the actions.
One workaround is to add an action at the end to run something like "ok.exe" and then have your other actions either create "ok.exe" (good result) or delete it. (bad result)
This way when the Task Scheduler goes to run the last action it will fail to start it (if you had removed it, because your previous action failed). This will cause the Task Scheduler to go ahead and Queue up your Task for a restart based on the restart settings on the Scheduled Task.
PS: To create a dummy ok.exe, I usually just copy c:\windows\system32\clip.exe c:\mytask\ok.exe
-- Tolga
So what is suggested is to create a final action for the task that will call a dummy .exe file. If the .exe file is not found, this will correctly cause the failure for the task and trigger the restart option. As .exe file he uses clip.exe from Windows system folder, this is nice I think because is very small and won't do any action if called on it's own.
Caution
I've tried with empty .cmd and .bat files but this will not trigger correctly the fail trigger. It must be a .exe file apparently.
Of course a mechanism to rename/move the ok.exe file in case your target script/job fails is needed.
I've pointed the Task Scheduler to use the wrapper script below with success. Edit the path to ok.exe as needed, I've copied it in the same directory as this wrapper script:
#echo off
:: This will reset the .exe name to make sure the .exe is available if error is
:: not triggered. See `:trigger_error`.
if exist ok.exe.nope (
rename ok.exe.nope ok.exe
)
:: This script is used as batch runner by Task Scheduler.
:: MAKE SURE THE SCRIPT WILL RETURN AN ERROR CODE !=0
echo Here is my script!
:: If script above exited with an error, rename the `ok.exe` file. This will
:: cause a failure for Task Scheduler following action attempting to run
:: `ok.exe`, thus triggering the restart conditions.
:: See https://social.technet.microsoft.com/Forums/Lync/en-US/4545361c-cc1f-4505-a0a1-c2dcc094109a/restarting-scheduled-task-that-has-failed#e4e3ff74-2d42-4d58-a930-a7838a0762ff
:trigger_error
if %errorLevel% NEQ 0 (
rename ok.exe ok.exe.nope
)

Resources