Mowgli
Mowgli

Reputation: 3512

Task Scheduled not running batch file

I have file which does somethings and it works fine if I run the file manually but it doesn't run when set up in task scheduler.

Batch file is in a folder on desktop on windows 7.

Any feedback will be helpful.

I've even tried this link solution didn't work.

Upvotes: 2

Views: 4874

Answers (3)

vernonner3voltazim
vernonner3voltazim

Reputation: 786

I don't know if this will help, but in bashing my head against one problem after another for far too many hours, I finally got my own batch file to work properly as a scheduled task. Some of the things I learned in the process:

  1. If you are the user who has created the scheduled task, you must also be a user who has logged into the system using a password.
  2. Any reference to a file name, inside the batch file, needs to be the last part of fully qualified path, starting with drive letter.
  3. If you do a comparison, like [%flag%] EQU [0], be aware that the "[" and "]" symbols are string literals that are included in the data that gets compared.
  4. If part of your batch file sets a variable and includes a "FOR" loop that calls a subroutine in which you expect to change the variable, you need to make sure that the variable is originally initialized as early as possible in the batch file. That is, something like this:

    IF ... (
      SET %flag=0
      FOR ... (CALL :subr)
      IF [%flag%] EQU [1] ( main scheduled-task command goes here)
    )
    GOTO :eof
    
    :subr
      IF ... (SET %flag=1)
    
    :eof
    

--worked from the command line, but not as a Scheduled Task. I had to move the initialization of %flag to be done before that very-first IF.

Upvotes: 0

ninjaPixel
ninjaPixel

Reputation: 6382

As a test, try moving the .bat file to a directory with basic permissions (maybe a shared directory for example).

I had the same problem as you. My .bat file was located in a folder with some restrictive permissions on it, so that only my user account could access it. Even though I had set up the task scheduler to use my credentials it still failed. Moving the .bat file to another directory sorted the issue.

Upvotes: 0

Andy
Andy

Reputation: 11985

Most likely in this case you need to make sure that the directory the script runs in ("Start in") is set correctly. Usually this is the same directory that contains your script. You can set this in the Scheduled Task's properties.

Upvotes: 3

Related Questions