Script run via scheduled task always times out, but script runs fine manually

ahoffman 1 Reputation point
2022-08-18T23:38:45.407+00:00

I set up a Windows Task Scheduler task to automatically run a .cmd script every day at a set time. This task has worked for a while, but recently every time it runs the scheduled task will timeout. I get the error "Task stopping due to timeout reached". However, I’ve set a pretty long timeout in the task, so it shouldn't be taking timing out (the task has an 8 hour timeout, and the script should finish running in about 40 minutes). Additionally, if I run the script manually, everything works perfectly.

I've run into this issue before, where I have a scheduled task to run this script, and the task suddenly starts timing out every time it runs. Same thing where running the script manually works with no issues.

I've tried restarting the server, and I've tried deleting the scheduled task and creating a new scheduled task with identical settings. This sometimes works, but eventually the task starts timing out again.

Here are the settings in Task Scheduler:

  • Run whether the user is logged on or not
  • Triggers
  • Begin the task: On a schedule
  • Daily
  • 8:30:00 PM
  • Recur every 1 days
  • Enabled
  • Actions
  • Start a program
  • Prgram/script: C:\Users\myUser\Desktop\script.cmd
  • Settings
  • Allow task to be run on demand (selected)
  • Stop task if it runs longs than 8 hours
  • If the running task does not end when requested, force it to stop (selected)
  • If the task is already running, then the following rule applies: Stop the existing instance
Windows for business Windows Server User experience Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MotoX80 36,291 Reputation points
    2022-08-19T01:39:44.623+00:00

    Are any of the programs that the script.cmd runs GUI? That is, do any display message boxes? Or are they all console based command line programs that write to stdout/stderr?

    See my reply in this thread.

    https://learn.microsoft.com/en-us/answers/questions/971208/windows-task-scheduler-shows-error-0xe0434352.html

    Configure the task to capture stdout and stderr. In the command file echo the start and end times so that you can see how long each execution takes.

    If your cmd file is calling some executable, run a tasklist and verify that you don't have orphan programs.

    tasklist | findstr -i yourprogramname  
    
     
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.