5

I am running a daily task on Windows 10 Pro which is supposed to

  • wake the computer from hibernation
  • start cmd.exe, run a command script to copy a file to a network drive, create a log file
  • shutdown the computer

When starting the task manually from within the task scheduler, everything is executed as intended.

When leaving the computer in hibernation mode, the task scheduler wakes the computer at the specified time, but apparently the command file (.cmd) ist not executed at all. No log file ist created, no file is copied, and the computer is not shut down. The task is marked as "successfully completed with the return code 2147942401" which is hex 0x80070001. This error code seems to indicate an "illegal function", but I have no clue what that might be, especially since the task runs fine when started manually, as said.

Here's an overview of the task settings (translated from German, but it should be clear):

  • General: execute regardless of user login; don't store password; highest privileges; configured for Windows 10

  • Actions: start program cmd.exe; arguments: /c "path-to-cmd-script\script.cmd >> logfile.txt"; start in: empty

  • Conditions: reactivate computer

  • Settings: allow execution if needed; if execution fails restart every 10 minutes; end task if execution longer than 3 days; force ending of active task if not stopped on request; don't start new instance

I have another task doing a backup with exactly the same setting which is running fine (wakes up, runs a script, then shuts down computer).

Any hint highly appreciated, questions welcome.

3
  • "start in: empty" does script.cmd have write permissions in the directory where is being run? Have you tried specifying a directory here?
    – DavidPostill
    Jan 28, 2017 at 9:25
  • Later today: yes I added the path, but to no avail. Same return code. cmd.exe not executed. It ist probably staring at me, but I can't figure out what's going on :-( Does anybody?? No I haven't tried that, but I shall. The other task which is running fine doesn't specify the path either (both scripts are in the same directory). I'll report tomorrow. Jan 28, 2017 at 16:43
  • 1
    The reported error code 2147942401 is really Windows' way of saying "code 1". The other bits are metadata, according to my ops guy. It says 2147942499 when you return 99. Jun 29, 2021 at 5:59

3 Answers 3

2

Actually, no. However, I have used the simplest task scheduler settings and now it works.

General:

  • use only when user is logged in
  • use highest privileges
  • configure for Windows 10

Action:

Program/script: C:\Windows\System32\cmd.exe
Arguments: /c <your batch file with parameters>

Conditions:

  • re-activate computer

Settings:

  • allow execution if needed
  • execute as soon as possible if start was missed
  • if task fails, restart every 5 minutes
  • terminate task if execution exceeds 3 days
  • force termination if not stopped on request
  • stop current instance if task already running

Now it's running every day at the specified time for months.

1
  • 1
    This answer starts with "Actually, no" but I don't see a yes/no question posted here.
    – Jik
    Dec 31, 2020 at 11:03
1

Powershell is finicky with scheduled tasks. I have burned through many hours with this. Following is a method I use to troubleshoot using the tried and trued batch file.

Try creating an intermediate batch file and have the batch file call the powershell. With the batch file you can do a bunch of echo's that you can output to a log. This will allow you to see the complete stdout/stderr for the process. This may help troubleshooting in more detail.

The log can be created by appending to the scheduled task arguments > "<path_to_log_file>" 2>&1.

0

For me, the task would sometimes work and sometimes wouldn't. According to the Scheduled Task History, when failing, it would appear as if it's been running for about 40 seconds, doing nothing, and completing action "C:\windows\SYSTEM32\cmd.exe" with return code 2147942401.

  • In this case, there was no point messing with the Group Policy settings because sometimes it would work, but not everytime (see https://stackoverflow.com/questions/48343993/batch-file-from-scheduled-task-returns-code-2147942401/).

  • Simplifying, recreating, reconfiguring my task did not fix the problem.

  • I did also consider butchering my batch file and getting rid of the standard output redirection, thus abandonning the logging capability (and becoming blind). Or simply running an actual .exe process, instead of using a batch file at all. This could have been a solution.

  • I also considered replacing the "on startup" scheduled task by a service, which would have been a fairly expensive experiment for such a trivial problem.

Ultimately, I considered adding a delay on the scheduled task and looked for configuring my task like a delayed service—services can either be "Automatic" or "Automatic (Delayed Start)". For "At startup" scheduled tasks, it's the trigger that have individual properties of its own, including the capability to add a delay:

Image depicting solution for delaying an on-startup scheduled task

I believe my scheduled task was sometimes being started a few milliseconds too early and some OS service or functionality was not yet available or allowed. Simply adding a small delay on the trigger fixed the problem.

You must log in to answer this question.

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