Scheduled Task not launching .bat or .cmd file (Win2K)

Hi all,

I have some Windows 2000 servers that I would like to run a .bat or .cmd file with (the .cmd file is basically the robotask version of the .bat file, since .bat hasn't been working) that xcopy's an SQL dump file to an offsite NAS box. If I run the .bat file or .cmd file manually, it works just fine. If I try to run it from the scheduled task, it runs with an empty status and 0x0 in the result field. The .bat and .cmd files were created using the Administrator account, as was the scheduled task (which has the password set as well). The .bat and .cmd files have full permissions set for everyone and Administrator to have full control, and Administrator is the owner.

-All files and tasks created as Administrator
-All permissions are set up correctly
-Tried using full UNC paths in the task, ie: \\servername\c$\etc...
-Tried putting the .bat and .cmd files in the system32 directory
-All tests have been with small log files that are <3MB in size, not the full 15GB database dumps.

What else can I try so that I may get this task to actually run, as well as put the files up on the NAS box? (The NAS box has proper permissions set, too. As specified before, manually launching the batch files works just fine).

FYI: I'm running these tasks as administrator because it's no problem that they run with full priority. It's starting at 11pm and will finish by 6am, so it's not during working hours.
Who is Participating?
Gerwin Jansen, EE MVEConnect With a Mentor Topic Advisor Commented:
>> but, again, manually running the batch right after works
Do you mean: starting the batch file from the task scheduler or starting it by just opening it in the Explorer?

>> It's only when the scheduler tries to launch that batch file when the issue arises
Can you add this line to the batch file to test if it's got to do with access rights:
dir \\<nasbox>\<share> >> %TEMP%\nas_share_contents.txt

Open in new window

When you see the contents of your nasbox share in the .txt file, the task scheduler launched job is working properly, if not the scheduled job does not have the same 'rights' as your local admin account starting the batch job.
The status empty and the result 0x0 means that the task was executed correctly, at least without errors. Not that the bat do what supposed to do.

You can try to run the commands in the bat file to send results to a txt file,  adding at the end of every line in the bat

>> log.txt

and review the log.txt to trace the bat.
howejustinAuthor Commented:
Thanks for the reply, but again, the problem is not with the batch file. I can run the batch file manually and it completes without any problems, so outputting each line of syntax to the log file will not do anything helpful.

The problem is that even though it's resulting in a seemingly OK status and result, it's not actually running the batch file.
Protect Your Employees from Wi-Fi Threats

As Wi-Fi growth and popularity continues to climb, not everyone understands the risks that come with connecting to public Wi-Fi or even offering Wi-Fi to employees, visitors and guests. Download the resource kit to make sure your safe wherever business takes you!

Gerwin Jansen, EE MVETopic Advisor Commented:
Hi howejustin, I've seen issues like you experience before. Mostly caused by the fact that the task scheduler is running under local (admin) or system credentials preventing access to (file) shares or NAS boxes in your case.

I have a generic solution for this where I run a simple batch job under the same account that you use to run your task manually. The batch job checks for existence of a 'trigger' file, if it finds one it launches a 'payload' batch file, in this case your .bat or .cmd file after which it removes the trigger file and sleeps for some time. To get this running, I create one (or more) scheduled task(s) that only create(s) the 'trigger' file(s) at the required time.

Note that the task scheduler is only used for timing the actions. The user that is logged on can create all kind of drive mappings, connections etc. and start the batch job that will trigger the actions.
howejustinAuthor Commented:
Thanks for the reply gerwinjansen, though I'm not positive the issue isn't with task scheduler itself. The batch file runs fine manually, meaning that there is no problem for the local admin account to access and transfer files to the offsite NAS box. It's only when the scheduler tries to launch that batch file when the issue arises (but, again, manually running the batch right after works).

Could it be an issue with setting the task up, and logging in with an RDC session to the Windows 2k server instead of being locally logged on? Unfortunately, win Win2K you can't log on with console, or we would have done that.
howejustinAuthor Commented:
Thanks again gerwinjansen,

We're getting somewhere now. I added the directory output to text file, ran it manually (through explorer), and it showed the contents of the shared NAS directory. I then deleted the text file, ran it from scheduled tasks, it created a blank text file. I then created a new user BatchUser and added it to the administrators group, logged in as that user, then ran the batch (through explorer) and it worked fine. Then I created a new task, took ownership, and ensured that BatchUser had full control in security, but it did the same as before...a blank text file.

Where else am I forgetting to set the appropriate permissions for the scheduled task to access the directory?

You know what, I just thought of adding the login credentials to the batch file itself for the NAS box. Let me try that and I'll let you know.
howejustinAuthor Commented:
Alright, your final paragraph prompted me to also try creating a user with the same credentials as the NAS box, then running the task as that user. Worked great. Thanks!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.