For the life of me, I can't seem to get a batch file running in Server 2008 Task Scheduler, despite it not having the common problems I've seen before.

Problem so far:

  • I have a batch file that takes a hotcopy backup of some repositories and ZIPs them. I am able to run this manually.
  • I have created a task in the task scheduler to call the batch file (no quotes, no command-line args).
  • No matter what, the task returns with Code 0x1 (which I believe has something to do with permissions).

Troubleshooting steps so far:

  • Ran the task manually. Runs perfectly.
  • Made sure I didn't have quotes in arguments due to the 2008 Server hotfix bug outlined previously on ServerFault. I have not only no quoted arguments, but no arguments.
  • Redirected output to a log file to see if it was running. It isn't.
  • Changed the user from the System Service account to the local Administrator account for testing purposes. The Administrator account has all necessary rights & privileges, and is currently logged on when trying to run the task manually.
  • Created another batch file which does nothing but call the other batch file to see if it was somehow maybe a command in the batch file that is initially called. This still fails, but again works if run manually.

I'm at a dead end. Any new thought that could jump-start the troubleshooting process? Thanks!

Edit 1: To clarify, I should note that I'm checking "run task whether user is logged on or not", but I do not remember if it was set up that way initially.

  • Do you have the check mark for only run if user is logged in? I did that once :(
    – Nixphoe
    Aug 3 '11 at 19:21
  • @Nixpoe: good point. Maybe he should try to recreate the Task from scratch.
    – jftuga
    Aug 3 '11 at 19:30
  • @goober: what do the event logs say?
    – jftuga
    Aug 3 '11 at 19:31
  • @Nixope, I've clarified the question; I have "run whether user is logged on or not" checked, as this is the behavior I wish to achieve. Aug 3 '11 at 19:48
  • @jftuga, I cannot seem to find any associated events in the Event Log after looking through. Is there a specific section you can point to? Aug 3 '11 at 19:48

I have the same problem. This is what I checked. What is the name of your batch file? Could it be a .bat? Try renaming it to .cmd SQL Server agent is running the job. Does the service account for that service ha rights? Do you use a call statement or do you just write the name of the batchfile? I think you do not need a call statement (you mentioned it). Is the owner of the job sa. This is normal today. Do you have any net use commands or copy del etc that needs /Q /Y or other statements? The job cannot answer any questions like there are open files are you sure etc. Is there a windows firewall involved? My gotcha was: I tried to do more than one thing in the job. Don't. Rename one thing with one job. Rename another thing with another job. Don't do more than one thing with each job. Sounds stupid I know, but you should do it anyway for troubleshooting purpose. easiest way to test something is net use z: \server\share and see what you get in the event viewer and job history log. Keep it simple then enter a real command. I am very sorry it does not work like it did before when it was top-of-the-line.

  • Good TShooting technique
    – Citizen
    May 28 '16 at 21:02

Troubleshoot your task by running as the same user that your task is set up for. For instance, if you're logged in as JoeUser, but your task is running as local administrator, you would need to runas /user:administrator cmd and run your batch from there. There may be some difference in the path, environment variables or permissions which are causing problems.

Also, the return code of 0x1 from a batch program is just reflecting the return code of the last command issued in the batch program before it terminated. For some programs, 0x1 is an error. For others, it's just a return code -- check the documentation for the particular command. You can insert an echo %ERRORLEVEL% after commands in your batch file to trace the progress and help you narrow it down. Once you know which command is returning the 1, you can check the documentation for that command to see how to address it.

Once you have it running properly in a CMD window running as the same user you intend to schedule it as, then you can move on to running it as a scheduled task.

Perhaps you could clarify what the nature of the batch program is to help us answer why it's failing to run as a task.

  • The question is 3 yrs old. Just sayin', the OP may have moved on to later versions. Mar 27 '15 at 8:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.