15

I have a batch file on a Windows 2008 server that, when invoked from command line works fine. However, when I set a scheduled task to run this job, it does not work properly.

The task scheduler does show that that the task is getting run at regular intervals, it does not show any error. But, the batch file does not process what it is supposed to process.

Any ideas on how to fix this issue is most welcome

shikarishambu
  • 2,219
  • 6
  • 35
  • 57
  • Under what user the bat file is set to run? It may not have the required permission. It wont show any errors but will not run. – Shoban Feb 22 '11 at 23:08

4 Answers4

25

Windows Server 2008 will not run any batch file with quotation marks " inside the batch file. See http://technet.microsoft.com/en-us/library/dd851678.aspx

Kevin Stewart
  • 266
  • 3
  • 3
  • 2
    This guy should get a medal!!! Thanks to this answer I could make everything work. A simple workaround I found is this: you create another batch file which you should name something like "DummyCaller.bat" with only one line: a call to your other batch file (for example: call mybatch.bat). MyBatch.bat is your original bat file which contains the quotation marks and didn't work. However, if you call it this way, it works perfectly. – Gaspa79 Jul 19 '12 at 15:12
  • 5
    OR you can download the hotfix HERE http://support.microsoft.com/kb/951246 – Gaspa79 Jul 19 '12 at 15:21
13

I had a similar problem, my .bat file wouldn't correctly execute when I had the full file path in the "Program/script" field.

"D:\path\to\file\somebat.bat" didn't execute. (with quotes)

When I put D:\path\to\file\ (without quotes) in the Start in (optional): field and somebat.bat in Program/script: field somebat.bat executed correctly.

Go figure... not exactly sure why having "D:\path\to\file\somebat.bat" in the Program/script: won't work.

Maybe someone could shed some light on that?

payling
  • 2,466
  • 5
  • 33
  • 44
  • 1
    Thanks so much! I have been up and down all the permission settings for my .bat file and the folders it was in and nothing worked until I tried this tip. – IcyBlueRose Jan 26 '12 at 20:50
  • This was it, despite copying from another task where it worked fine. What a time waster. Thanks for the answer. – markau Oct 02 '15 at 04:40
6

In my case, I had 'Run whether user is logged on or not'. When I changed to 'Run only when user is logged on' it worked OK.

Frank Yates
  • 69
  • 1
  • 1
0

Make sure the task is running under an account with the necessary privileges. When you run a batch script from the command-line directly, it is running under your user account, which may have different permissions than the default account used for scheduled tasks.

mellamokb
  • 56,094
  • 12
  • 110
  • 136
  • Task is running as Administrator. I saw an article that said it is not enough if the group has access to the directory, the user should have access to the directory directly. So, I did that, too. No change in behavior – shikarishambu Feb 23 '11 at 00:19
  • How about changing your batch script to write to log files when ever an action is complete. This way you can narrow down to the step which is causing the error. – Shoban Feb 23 '11 at 00:24