13

I'm using Windows Server 2003 and have a scheduled task that fails to complete. The task is set to run a Windows Command Script (.cmd) at 3pm each day. The script runs a program that extracts some data from a SQL Server database and uploads that data to an FTP server.

The error code displayed in the "Last result" column of the scheduled tasks folder is 0xc000013a. A quick Google search leads to this Microsoft support page that states: The most common "C" error code is "0xC000013A: The application terminated as a result of a CTRL+C".

No-one is logged in at the time the task runs, so there's no-one around to press CTRL+C. I'm not sure I understand what is being said here in the Microsoft documentation.

I've checked the rudimentary things - the scheduled task is enabled, scheduled to run each day, and pointing to a file that does exist in a valid location. Interestingly, when I run this task manually (either by running the .cmd script from the command line, or by right-clicking the task and clicking "Run") the task completes successfully.

What does this error code mean, and how can I get this task to run when I'm not there to force it?

1
  • Try to add an exit code to the end script by yourself (e.g. exit 0). If it still fails, it's failing by itself. If not, it was just a bogus exit code misinterpreted by the task scheduler.
    – bjoster
    Mar 6, 2018 at 16:35

11 Answers 11

7

Troubleshooting scheduled scripts:

  1. If you haven't already, check the Scheduled Tasks log file, in the GUI under Advanced > View Log. Search the file for "***" to find the most recent entries, and you may see a little extra error info.

  2. Define a log file to capture output, and send both standard out and standard error there. Change any echo OFF to echo ON to be sure you're not supressing any error messages.
    For example, if your script is called ftp.data.cmd then your scheduled task might look like this,

    cmd /c ftp.data.cmd >> ftp.data.log 2>&1

  3. Is the script hanging? Maybe the task scheduler is killing the script (hence the CTRL+C error code) after some specified period of time. Add some of these at strategic points in your scipt,

    echo %DATE% %TIME%

  4. Are you sure the account running the script has permissions / access to everything in the script?

  5. If you can't get any joy, run this command and post the output here, maybe we can start with the scheduling,

    schtasks /query /v /fo LIST /s YOURSERVER

4

I can't answer the question directly as I don't know specifically what the error message means (nor, therefore, how to fix it), but if I were trying to troubleshoot it I would add a few writes to a log file at strategic points in the script and then after the scheduled time see what the last checkpoint to run is.

My suspicion would be that there's something that's failing due to the credentials the script is running under or something in the script needs a logged-in user. Narrowing down where in the script things fail might help you find the "offending" code.

2

I realize this is an old posting but they're very helpful when searching for solutions and maybe what I found can be helpful too. I was using WinSCP on Windows Server 2003 to upload to an ftp server and received the same error message and the SchedLgU.txt file pointed to not enough time in the "Stop the task if it furn for:" section even though I gave the task plenty of time to upload.

Looking in Task Manager I could see that WinSCP.exe wasn't clearing out and I had tons of the processes in the list, so I created a batch file (taskkill /f /im winscp.exe) to kill any opened process and I have that batch file run before the WinSCP and it works well now.

2

I ran into this today on a remote server, and the solution was to change the run setting from "Run only when the user is logged on" to "Run whether the user is logged in or not".

With "Run only when the user is logged on" the task launches a command window that was closed when my remote desktop session timed out. With "Run whether the user is logged in or not" no window is displayed while the task runs, so the execution does not stop when my remote desktop session ends.

1

Similar to cori's answer I would recommend that you check who the scheduled task is set to run as, as I have seen this error occur when the user account that is running the task doesn't have the same permissions as the logged in user

1

If this ran before, perhaps a condition like a network outage or a problem on another host can explain the failure.

1

I had the same error and it was because the batch file I was running was prompting for some files to delete with DEL command. As there is no user to answer Y/N to batch process the scheduled task is terminated. The following is the message I have found on my scheduled tasks log: "the task was terminated. This action was initiated either by an administrator or by the Task Scheduler service (because, for example, the computer is now non idle)." My recommendation is to run the task manually from the command prompt to see where it is stopping or prompting for some user interaction, correct it and your task will run fine.

1

If you are trying to run the program under Task Scheduler control, the System.Environment.CurrentDirectory will return C:\Windows\System32, NOT where your executable is located. This error can be a file-not-found error; I was trying to log to a subdirectory and it didn't exist in the System32 tree.

0

At my scripts this is clear. It happen's cause i have "pause" at the end of batch file and scheduled task is limited to 20 minutes. When user is present, hi can see flow of the job. When isn't batch file is terminated by scheduled task, after 20 min. This is causing 0xc000013a and it's ok.

0

I had the same issue and fixed it by changing the trigger from "On system startup" to "On logon".

0

had the same problem.. fixed by playing with user who is registered to run the scheduled task. in the end, changing the domain was the answer.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .