How to run a task with task scheduler?

SSL Leiden 0 Reputation points
2025-01-07T14:19:30.0833333+00:00

I have created a task with task scheduler. The command executes fine from command prompt.

When the task is triggered, it just returns error 0x80070002.

The task history shows error 2147942402.

The task history also says that the user is 'SYSTEM', even though the task should run as my local account. Neither do I checked to have it run with admin privileges.

Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
10,451 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MotoX80 35,051 Reputation points
    2025-01-07T15:09:41.2933333+00:00

    0x80070002 is "file not found". You may need to specify the full path to the executable.

    Use a .bat file to execute your program and configure the task to capture stdout and stderr into a log file. Then review the log for errors.

    Modify the task action like this example. Use your file/folder names.

    cmd.exe /c c:\Scripts\Test.bat 1>c:\Scripts\Logs\Test.log 2>&1
    

    User's image

    Set the task to execute as the desired user.

    User's image

    If you want the task to only execute when the user is logged on, select "run only when the user is logged on". You will not need to enter a password, and when the task executes it's window will be visible on the desktop.

    If you want the task to execute no matter who is logged on to the desktop, select "run whether the user is logged on or not". You typically would enter a password, and when the task executes it's window will NOT be visible on the desktop. Mapped network drives may not be mapped, you should use UNC path notation, \\ServerName\ShareName\FolderName. Do NOT run GUI programs like Excel in this configuration. If the task does not need to access network resources, then you can optionally set "do not store password".


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.