Task Scheduler on Windows Server - 0x2 error

Iron Contributor

We have several terminal servers (2019), and on all of them there are some Excel addins in use which can be temperamental and need a reboot if they give trouble. Therefore, I've created a scheduled task on the management machine which reboots the terminal servers in the middle of the night. That bit seems to work fine.

 

Several years ago I noticed that sometimes the connection broker service would start then immediately stop randomly after the reboot, and would not restart automatically. I therefore created a batch file to manually start it (containing one line - net start tssdis) and scheduled that individually on each terminal server, to run 15 minutes after the reboot. And it seems to have worked for several years.

 

However, now I am getting the task failing with an 0x2 error (which also happens if the task is run manually), and I've tried everything I can find suggested online - with or without speech marks in the fields, with or without the Start in field filled in. The task has always run with the highest privileges, using an admin account, and set to run whether or not the user is logged on.

 

I have also tried cutting out the batch file and putting net or net.exe in the program/script field, and start tssdis in the arguments, putting "net start tssdis" with speech marks in the program field with nothing in the arguments field, and putting C:\windows\system32\ in the Start in field. Nothing works - the task continues to return a 0x2 error.

 

Can anyone suggest anything else to try? This is not a complex requirement and it's rather ridiculous that it seems impossible to get it to actually work! Thanks.

 

8 Replies

@DavidYorkshire 

 

Event Viewer would tell you the most about what's going wrong. The Task Scheduler MMC makes the event log easier to navigate by filtering events under the defined job's History tab (which I suspect you already know but put here for the benefit of others.)

 

0x2 means "file not found", which is odd. Since %windir%\System32 is - at least by default - part of the system-wide PATH definition, there shouldn't be any issues finding "net" (or net.exe), but clearly you're running into issues finding whatever it is you're using for the 

 

Have you tried specifying the full path to net.exe in the "program/script" section, as per the example below? (Forget about my argument and use your own - that's not really relevant.)

 

Incidentally, the working directory won't help you resolve path issues. It's relevance is a different topic altogether. "Run with highest privileges" is also irrelevant in this case. "File not found" is a very explicit kind of error.

 

LainRobertson_0-1653455146919.png

 

In your case, you'd drop the "start tssdis" into "add arguments" - just as you described in your original post.

 

Cheers,

Lain

 

OK, looking at the task scheduler logs in event viewer (with the task set to run the batch file, as that is how it used to work), I see the following:

  • Task Scheduler launched "{removed}" instance of task "\StartTssdis" due to a time trigger condition.
  • Task Scheduler launch task "\StartTssdis" , instance "C:\Windows\SYSTEM32\cmd.exe" with process ID 1060.
  • Task Scheduler started "{removed}" instance of the "\StartTssdis" task for user "removed".
  • Task Scheduler launched action "C:\Windows\SYSTEM32\cmd.exe" in instance "{removed}" of task "\StartTssdis".
  • Task Scheduler successfully completed task "\StartTssdis" , instance "{removed}" , action "C:\Windows\SYSTEM32\cmd.exe" with return code 2147942402.
  • Task Scheduler successfully finished "{removed}" instance of the "\StartTssdis" task for user "removed".

Shows in task scheduler as a 0x2, so failed for no clear reason (the batch file it is calling definitely exists).

If I change the task as follows:

DavidYorkshire_0-1653468328148.png

 

it also fails with a 0x2. In event viewer:

  • Task Scheduler launched "{removed}" instance of task "\StartTssdis" due to a time trigger condition.
  • Task Scheduler launch task "\StartTssdis" , instance "%windir%\system32\net.exe" with process ID 11736.
  • Task Scheduler started "{removed}" instance of the "\StartTssdis" task for user "removed".
  • Task Scheduler launched action "%windir%\system32\net.exe" in instance "{removed}" of task "\StartTssdis".
  • Task Scheduler successfully completed task "\StartTssdis" , instance "{removed}" , action "%windir%\system32\net.exe" with return code 2147942402.
  • Task Scheduler successfully finished "{removed}" instance of the "\StartTssdis" task for user "removed".

So I'm really not seeing what's causing this. Looking online, it's clear that the 0x2 error despite the file definitely existing is a long-standing common issue.


 

@DavidYorkshire 

 

This is where monitoring with Process Monitor (procmon from SysInternals - now operated by Microsoft) would provide real clarity.

 

But I have seen a similar, very rare issue before albeit in a different context to what you're doing with net.exe, so I'll throw this out there as an option to try (in the Hail Mary category.)

 

Try creating the following two directories:

 

  1. C:\windows\system32\config\systemprofile\desktop
  2. C:\windows\syswow64\config\systemprofile\desktop

 

You should create these from an administrative command prompt to avoid the additional permissions Windows Explorer adds, but to each their own.

 

At the end of the day, a file or directory is definitely missing, it's just a case of determining what it is. If you are game to give it a try, ProcMon (mentioned above) will answer that question for you.

 

Cheers,

Lain

Created the first of those directories, from an administrative command prompt. Second one already existed.

Doesn't seem to have made any difference - task is still giving a 0x2.

Thanks

@DavidYorkshire 

 

Yeah, fair enough - it was only an educated guess at best. Task Scheduler could be looking for anything (though probably something related to creating the session environment passed into the CreateProcess call.)

 

Within Process Monitor, you can configure a filter like the one shown below to find what is missing. There's not much value in me making further guesses on what the missing component might be.

 

Ideally, you want to:

 

  1. Set up the filter first while paused;
  2. Make sure the history has been cleared;
  3. Start the capture;
  4. Start the scheduled task;
  5. Stop the trace once complete (should only take seconds to fail);
  6. Check the results.

 

The only display filters you'd want to check out are the files and registry filters, and even then, possibly just one at a time if the number of returned rows is significant.

 

Process Monitor filter

LainRobertson_0-1653610270119.png

 

Example results, also showing the display filters

LainRobertson_1-1653610413124.png

 

Cheers,

Lain

@DavidYorkshire 

 

Hello DavidYorkshire,

 

I hope you are doing well!

 

There is no need for you to worry about a 0x2 error in the task scheduler. It's quite easy to fix it. However, you will have to follow the below steps to encounter the task scheduler issue.

 

The task scheduler executes the .cmd or .bat files, which have to be performed with the administrator's help. The administrator gives access to the administrative rights to run the tasks from the assigned account to save time from scheduling them daily. However, even if the rights have been given, sometimes it fails to perform the duty. As a result, the last run result of 0x2 failed because access had been denied.

 

In order to fix the issue, firstly, we need to know the cause of the issue. 

 

The error 0x2 result means that the file could not be found. Thus, make sure that when the Task starts, the batch file exists and is accessible. Also, it means "Access denied"; thus, you must check if you were facing a permission issue.

 

We can fix this issue in two possible ways:

 

1) Fix the issue with the help of a repair tool kit:

 

  • Download the repair tool kit from the browser.
  • Follow the prompts and install the program. On the welcome screen, you should untick the automatic scan option.
  • Now, Click on install.
  • After the installation process, the software will automatically scan your PC and show the damaged areas in your PC which have to be fixed
  • Click on the Repair button to fix the task scheduler error.
  • Restart your PC.

 

2) Override the properties with the least privileges:

 

You can also try to configure the Scheduled Task to Run with the highest privileges in the Properties dialog of the Task.

  • Double click on the particular Task, and go to properties.
  • Kindly change it to Run with the highest privileges and click on OK.
  • Enter the password.
  • Thus, it allows the tasks to run without any error code.

If the problem persists, then try below to fix it,

 

You will have to disable logging in your robocopy script as it may create problems whenever the scheduler runs a task.

 

You must ensure that the file path you have given is correct because an incorrect file path can cause a 0x2 error. Also, check the permission as it can also be a reason for the error.

 

I hope the above fixes work for you, but if the problem persists, then we'll investigate further to overcome the error.

 

----------------------

Regards,

Austin_M

@Austin_M 

 

Access denied is 0x5, not 0x2. You can validate that for yourself using the following method.

LainRobertson_3-1654264973781.png

 

You also do not need administrative rights to run scheduled tasks that run within cmd.exe.

 

Quick demonstration below.

blah.bat

@echo off
echo Hello from cmd.exe
pause

Scheduled task definition, created as an unprivileged user

LainRobertson_0-1654264735126.png

 

LainRobertson_1-1654264781893.png

Running the scheduled task as the unprivileged user

LainRobertson_2-1654264879210.png

 

Cheers,

Lain