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

Posted on 2011-10-10
Last Modified: 2012-05-12
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.
Question by:howejustin
    LVL 12

    Expert Comment

    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.

    Author Comment

    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.
    LVL 37

    Expert Comment

    by:Gerwin Jansen
    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.

    Author Comment

    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.
    LVL 37

    Accepted Solution

    >> 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.

    Author Comment

    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.

    Author Comment

    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!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Transparency shows that a company is the kind of business that it wants people to think it is.
    Email signature management is something that is often overlooked in many organizations or is simply not implemented effectively. Let's take a look at what methods are available for managing this important piece of corporate branding.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now