227

I have a batch file daily.bat, this is the code:

cd C:\inetpub\wwwroot\infoweb\factuur\cron
c:\PHP\php.exe -f ./cron_pdf.php
ftp -s:ftp_upload.txt ftp.site.be

And I created a task with task scheduler in Windows 7. When I run the batch manually, everything goes fine, but when I try to run it with the task scheduler nothing happens.

My action is

'run script' "C:\inetpub\wwwroot\site\x\cron\daily.bat"

UAC is off and I am Admin.

Any idea why this is not working?

2

18 Answers 18

412

I faced the same problem, but I found another solution without having to modify my batch script.

The only thing that I missed out is at the 'Action' settings - "Start in (Optional)" option.

Go the task properties --> Action tab --> Edit --> Fill up as below:

  1. Action: Start a program
  2. Program/script: path to your batch script e.g. C:\Users\beruk\bodo.bat
  3. Add arguments (optional): <if necessary - depending on your script>
  4. Start in (optional): Put the full path to your batch script location e.g. C:\Users\beruk\(Do not put quotes around Start In)

Then Click OK

It works for me. Good Luck!

Sign up to request clarification or add additional context in comments.

9 Comments

I don't believe you actually need the 'Start in (optional)' value - I am able to run a simple, self-contained .bat file without it. Thank for the clear steps though - very helpful for those looking for a simple walk through!
Worked like a charm on Server 2012 as well.
@DCaugs, Without the Start In parameter set, my scheduled batch file would not run at all. (Windows 7)
With a scheduled 'foo.cmd' task on Windows Server 2012 with 'Start in' set to 'C:\Foo\' the task failed with exit code error 0x8007001, but with 'Start in' set to 'C:\Foo' the task ran fine.
@DCaugs The Start in is the main reason it worked for me.
|
96

None of the above method worked. I tried it this way as said it in a tutorial and it worked.

Action:

Start a program 

Program/script:

cmd

Add arguments:

/c start "" "E:\Django-1.4.1\setup.bat"

Worked for me on Win7 Pro. You must have an account with a password (blank passwords are no good)

7 Comments

This method worked for me. But, in the scheduler, in the history tab, the task completes immediately with success, since the task is the cmd, but not the .bat file that it launches. Since the bat file, a backup operation, ends in 2-3 hours, I have no idea of its status.
u need to keep a mail notification at the end of the bat file completion to notify its status. thats one way.
This worked, in conjunction with the tip that it should be set to run in a specified directory as mentioned in @Ghazi's accepted answer, making sure that "run with the highest privileges" are also selected.
I know this thread is quite old now but in response to @azzurroverde 's problem, you can just add a /wait to the parameters for the start command
The above solution didn't work for me on windows server 2019
|
64

For those whose bat files are still not working in Windows 8 and 10+ Task Scheduler , one thing I would like to add to Ghazi's answer - after much suffering:

  1. Under Actions, Choose "Create BASIC task", not "Create Task"

That did it for me, plus the other issues not to forget:

  1. Use quotes, if you need to, in your Start a program > program/script entry i.e "C:\my scripts\runme.bat" (or just use the Browse button)...
  2. Use the Start In path to your batch file, even though it says optional - BUT DON'T use quotes in the Start In field. (Crazy but true!)

This worked without any need to trigger a command prompt. And it is the quickest and simplest method.

(Sorry my rep is too low to add my Basic Task tip to Ghazi's comments)

3 Comments

The nice thing about this method is the cmd window actually shows when the batch file is running (in my case, while backing up a Firebird database).
This worked for me in Windows 10 Pro
YES! Thank you - this saved my life! ;-) The important step is this: Under Actions, Choose "Create BASIC task", not "Create Task"
24

Make sure "Start In " has NO QUOTES.

Comments

11

Add a new Task in a folder


Logged in user vs Running in background


Add action


My script was to pull latest code from master and publish a new branch

cd D:\dev\repo
git checkout master
git pull
git branch -D my-branch
git push origin --delete my-branch
git checkout -b my-branch
git push -u origin my-branch
exit

1 Comment

I don't have rohit. Can't create a new item on that level either. Maybe show to choose drop down (Action->Create Task) ...
8

It is working now. This is what I did. You probably won't need all these steps to make it work but just to be sure try them all:

  • Check the account parameters of your scheduled task and make sure they are set to run whether or not someone is logged into the machine

  • check run with most privileges/rights

  • Make sure you go to the full path first: cd C:\inetpub\wwwroot\infoweb\factuur\cron

  • Don't use double quotes in your batch files (don't know why but seems to help)

  • Be super admin, enter 'Net user administrator /active:yes' in command prompt, log out and log in as the super admin, so UAC is off

1 Comment

Sorry to say, but this is a very poorly written answer. I would make sure the proper answer is selected as the accepted answer.
7

Make sure "Start In" does NOT end with a BACKSLASH.

3 Comments

Could you clarify what OS version or type of task or whatever this information is applicable to? The accepted answer includes a \ so it must work on some systems - where does it not work?
This fixed a scheduled 'foo.cmd' task for me on Windows Server 2012. With 'Start in' set to 'C:\Foo\' the task failed with exit code error 0x8007001, but with 'Start in' set to 'C:\Foo' the task ran fine.
This fixed for my case. I had start in as d:\ because the script is at the root of d drive. change to d: wihtout slash works
5

Had an issue where my task was not firing simply because it was running on a laptop without a power cord... Under the conditions tab, by default it is checked so that a task will not run while AC power is not connected.

Comments

3

Under Windows7 Pro, I found that Arun's solution worked for me: I could get this to work even with "no user logged on", I did choose use highest priveledges.

From past experience, you must have an account with a password (blank passwords are no good), and if the program doesn't prompt you for the password when you finish the wizard, go back in and edit something till it does!

This is the method in case its not clear which worked

Action: start a program
Program/script : cmd
      (doesn't need the .exe bit!)
Add arguments:
    /c start "" "E:\Django-1.4.1\setup.bat" 

Comments

3

I messed with this for several hours and tried many different suggestions.

I finally got it to work by doing the following:

Action: Start a program

Program/Script: C:\scriptdir\script.bat

Add arguments (optional) script.bat

Start in (optional): c:\scriptdir

run only when user logged in

run with highest privileges

configure for: Windows Vista, Windows Server 2008

Comments

2

If all of the rest fails for you here ensure that the user you are trying to run the task as has access to the file you're trying to use.

In my case I was trying to run a batch file from C:\Users\Administrator\Desktop which the account couldn't access. Moving it to a neutral location on C:\ resolved the issue.

Comments

1

Using the Run button in the Task Scheduler main window to test several variations finally found the correct settings. This two options must be combined: -Run only when user is logged on -Run with highest privileges. All other variations failed. It's infuriating all the time wasted on this, but at least it works. OS: WINDOWS 8 CORE (BASIC) VERSION

1 Comment

Same here, not sure why nothing worked on Win7 Ultimate SP1 until I found it myself, that I should select "-Run only when user is logged on", I didn't need to add "Start In", and I could select other user groups like Administrators, and it works just fine !
1

Please check which user account you use to execute our task. It may happen that you run your task with different user then your default user, and this user requires some extra privileges. Also it may happen that the task is executed but you cant see any effect because the batch file waits for some user response so please check task manager if you see your process running. Once it happen that I schedule a batch with svn update of some web page and the process hangs because svn asked for accepting server certificate.

Comments

1
  1. Don't use double quotes in your cmd/batch file
  2. Make sure you go to the full path start in (optional):
    C:\Necessary_file\Reqular_task\QDE\cmd_practice\

enter image description here

Comments

1

Just in case for anyone who might have missed this.

If you have set up everything correctly and the task is still not running and if you are on a laptop follow the steps to check

Select Task -> Properties -> Conditions Make sure under "Power" that the check marks are relevant , by default tasks will not start if you are not connected to AC power. You uncheck it to run it against battery power.power settings

Comments

0

Try run the task with high privileges.

put a \ at the end of path in "start in folder" such as c:\temp\

I do not know why , but this works for me sometimes.

Comments

0

Action: Start a Program

Program/script: C:\Windows\System32\cmd.exe

Add arguments: /k start "" "E:\scripts\example.bat"

Add exit to the end of your batch file.

The cmd window will not show if you select Run whether user is logged in or not. You need to select Run only when user is logged on to see the window in action.

Comments

0

In my case Windows has agreed to execute script only when I have resolved two "problems":

  1. I had to put into my script "cd C:/My_script_directory" before main execution.
  2. In the "Program/script" field I've put the full path with straight slashes, not the back slahes! "C:\My_script_directory\My_script.bat" -> "C:/My_script_directory/My_script.bat"

"Add arguments" and "Start in" fields were left empty. And Hurray! It's alive!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.