13

In the process of deploying our .net app, I've got about 20 scheduled tasks set up on a server, all of which basically do the same thing: invoke a small .net console app that pulls data from a SQL db and posts it to a web service. Each task invokes a separate copy of the app, each copy having a different lookup ID value in its config file.

All but two of these tasks run reliably every night. Two of the tasks seem to sporadically stop running from time to time, and it's currently a mystery as to why. When they stop running, the scheduled task interface correctly shows their last run date, which is a day or more behind the other tasks, which have continued to run at the scheduled time. The tasks which stopped running do not run again on their own, despite being indicated as scheduled to run every night. There are no errors recorded in the event log or in the scheduled task interface itself. And here's the strangest part to us: If I manually kick off the scheduled task, it runs fine, it invokes the .net console app and everything finishes without anomaly. And then it continues to run fine at its scheduled time, for days or weeks at a time, only to eventually fail, seemingly out of the blue. It appears both tasks always start to fail on the same night.

GEOCHET
  • 21,119
  • 15
  • 74
  • 98
David Korn
  • 1,091
  • 4
  • 12
  • 19
  • 1
    I think the answer to this question http://stackoverflow.com/questions/32589381/ could also help some people as to why tasks which run manually do not always run on schedule. (But from the way they're both described, these are not duplicate questions.) Summary: Windows 2012 Scheduled Tasks do not always see the correct environment variables, including `PATH`, for the account which the task is set to run as; in fact, they only see the full correct set of variables while the task user is actually logged in. – MikeBeaton Sep 17 '15 at 19:07

10 Answers10

11

There's a "Last Result" column that should give you a code related to the task itself running (it's not going to have any kind of exception data). 0 means the task completed without errors. Anything else you can look up and see why the task won't start. If the task still seems to not be running, but you still see a 0 for the Last Result, that means there's something broken in your code, but it's exiting gracefully.

scottm
  • 27,829
  • 22
  • 107
  • 159
5

Did you set "Start in" property?

If these .NET console apps need app.config or some files located into their path, you have to set "Start in" property to "c:\your\app\path\, otherwise they start as if they are in the system directory, and they cannot find files they need!

dar0x
  • 361
  • 2
  • 6
  • 10
4

Taskscheduler assumes on 64 bits systems that the applicaiton is 64 bit. If it is 32 bit launch it from the 32 bit command line, i.e. if you want to run c:\program files (x86)\Myprogram\Program.exe, tell taskscheduler to launch:

  • %systemroot%\Syswow64\cmd.exe /C "c:\program files (x86)\Myprogram\Program.exe"

This forces it to launch from the 32 bit command-prompt and hence with 32 bit emulation.

Richard Sitze
  • 8,262
  • 3
  • 36
  • 48
2

I found this super helpful link :https://windowsreport.com/windows-scheduled-tasks-not-running/ for thorough debugging steps for many use cases.

In my case user account with which scheduler was configured to run was locked that stopped execution of scheduled tasks without any logs or reporting problem.

enter image description here

Pranav Singh
  • 17,079
  • 30
  • 77
  • 104
1

The answer to the below SO question may also be highly relevant to people reading this question (but, NB, it describes only one possible specific problem with Scheduled Tasks and I believe neither of these questions is a duplicate of the other):

Why is my Scheduled Task updating its 'Last Run Time' correctly, and giving a 'Last Run Result' of '(0x0)', but still not actually working?

The summary of the answer given to that other question is that Windows 2012 Scheduled Tasks do not see the correct environment variables, including PATH, for the account which the task is set to run as.

In terms of more general Scheduled Task troubleshooting (as asked about in this question), you can test for this particular issue (e.g. running SET > test.txt in the task, as suggested in that answer), and once you can see it happening, you can work around it if it is affecting you.

Community
  • 1
  • 1
MikeBeaton
  • 3,314
  • 4
  • 36
  • 45
1

In my case, the scheduled task wouldn't run even though it said last run was successful (0). It turned out to be that the windows user account that was running the jobs had become locked out. I only realized this because I tried editing the existing scheduled task, set the user account to the same one, then hit OK and it gave me an error about the account being locked out.

Justin
  • 17,670
  • 38
  • 132
  • 201
1

One reason for Scheduled Tasks not running occurs when associating them with a password-less Windows user account: by default Scheduled Tasks are prevented from running with a blank password. If you want to run a Scheduled Task from an account with no password you have to disable a system variable:

  • Go to: Start > Administrative Tools > Local Security Policy > Security Settings > Local Policies > Security Options
  • Select: "Accounts: Limit local account use of blank passwords to console logon only"
  • Disable this variable

Disclaimer: It´s not recommended to have accounts with no password.

Ian Mackinnon
  • 13,381
  • 13
  • 51
  • 67
0

I discovered a similar issue February 23 2023 but my logs reveal it started mid January 2023.

My tasks had been working for many months without issue. The I began seeing the same error: The system cannot find the file specified. After all day testing and searching I found that a Windows update on Jan 10 2023 changed the way white space is handled. Formerly only needed one set of quotes. The command line help explains:

C:\> schtasks /create /?

==> Spaces in file paths can be used by using two sets of quotes, one set for CMD.EXE and one for SchTasks.exe. The outer quotes for CMD need to be double quotes; the inner quotes can be single quotes or escaped double quotes:

SCHTASKS /Create

/tr "'c:\program files\internet explorer\iexplorer.exe' \"c:\log data\today.xml\""

Dennis
  • 41
  • 5
0

Maybe they hung and were still running?

You can click on the extras-menu and choose the menu entry to view the log, then notepad will open a log file from the task planner

Christian
  • 2,903
  • 4
  • 31
  • 34
0

I found this page helpful when I was trying to trouble-shoot a misbehaving Scheduled Task:
http://support.microsoft.com/kb/308558

Select View->Details to show the additional information, like Last Run Time, and Status, and this page gave me the meaning of the status/error code:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms681381(v=vs.85).aspx

gkrogers
  • 8,126
  • 3
  • 29
  • 36