May 24 2022 03:37 AM
May 24 2022 03:37 AM
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.
May 24 2022 10:10 PM
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.
In your case, you'd drop the "start tssdis" into "add arguments" - just as you described in your original post.
May 25 2022 01:42 AM
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:
Shows in task scheduler as a 0x2, so failed for no clear reason (the batch file it is calling definitely exists).
May 25 2022 01:50 AM
If I change the task as follows:
it also fails with a 0x2. In event viewer:
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.
May 25 2022 03:26 AM
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:
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.
May 26 2022 07:49 AM
May 26 2022 05:16 PM
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:
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
Example results, also showing the display filters
Jun 03 2022 04:52 AM
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:
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.
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.
Jun 03 2022 07:03 AM
Access denied is 0x5, not 0x2. You can validate that for yourself using the following method.
You also do not need administrative rights to run scheduled tasks that run within cmd.exe.
Quick demonstration below.
@echo off echo Hello from cmd.exe pause