Running bat file using Windows scheduler

2

I wanted to run a .bat file in Windows task scheduler, so I opened it, added a new task, browsed to the bat file, and... nothing happened.

So I changed the timing to see if it'll run, and it didn't. Next I right-clicked on the task and chose "run", it didn't run. The file itself is only one line, basicly backups a folder to a another location. It runs fine when not in the scheduler.

When I asked on stackoverflow.com they first said to come here and the other guy said to write:

cmd.exe /C completepathtobatchfile argstobatchfileifany

So I wrote:

cmd.exe /C k:\backup.bat 

and it didn't work. What do I have to change to make it work?

bks

Posted 2009-10-06T17:46:24.310

Reputation: 201

Answers

2

I find it easier to just use the at command.

For example to run the batch file located at: C:\script.bat at 4 AM every Tuesday you would do the following in a command-prompt:

at 4:00 /every:T "C:\script.bat"

Ben S

Posted 2009-10-06T17:46:24.310

Reputation: 1 902

works great! thanks mate what does the ":T" do? – bks – 2009-10-06T18:07:22.830

T is for Tuesday – MDMarra – 2009-10-06T18:12:02.540

Yes, and Th is for Thursday. – Ben S – 2009-10-06T18:42:28.313

1what about doing that every day? or two days for that matter? – bks – 2009-10-06T20:46:21.870

0

After looking at several related answers on SuperUser.com, and not wanting to use a workaround, I finally found the answer on StackOverflow here: https://stackoverflow.com/a/13173752/261405

The important piece from there: At the 'Action' settings - "Start in (Optional)" option.

Without this, it would never work for me

Adrian Carr

Posted 2009-10-06T17:46:24.310

Reputation: 131

0

Two things:

  1. I believe that in XP a batch file must use full pathnames, e.g. "C:\utility\file.exe" instead of just "filename.exe". The batch file run from the scheduler does not necessarily have a PATH or a current directory. That's for executables and targets both.
  2. Also, in XP I believe that filenames are limited to the old DOS-style 8+3 system. Try reducing filename (and directory name) lengths to the short version.

CarlF

Posted 2009-10-06T17:46:24.310

Reputation: 8 576

Even in XP, any batch file in a path on your PATH should be found. – Phoshi – 2009-10-06T18:05:33.037

I was referring to using full paths INSIDE the batch file, not necessarily the path TO the batch file. – CarlF – 2009-10-07T04:49:08.580