215

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?

Ruben
  • 8,956
  • 14
  • 63
  • 102
  • Not sure if this question is offtopic but you might get better responses on http://serverfault.com/ for it. – Hans Olsson Dec 14 '10 at 09:41
  • Thanks I'll also try to post it on serverfault – Ruben Dec 14 '10 at 09:42
  • this can be usefull too: http://serverfault.com/questions/734035/running-a-batch-file-from-task-scheduler-without-user-being-logged-in – Ruben Mar 09 '16 at 14:17

18 Answers18

380

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!

Matthew Lock
  • 13,144
  • 12
  • 92
  • 130
Ghazi
  • 3,856
  • 1
  • 13
  • 3
  • 11
    I'm aware the original post is quite old. But this post was among the top link in google search when I was trying the answer for this problem. So I think I'd like to share the findings. Just in case, anybody including myself is forgotting this. – Ghazi Nov 01 '12 at 08:56
  • 5
    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! – DCaugs Sep 24 '13 at 18:11
  • 1
    Worked like a charm on `Server 2012` as well. – Avi Turner Apr 09 '14 at 09:41
  • 32
    @DCaugs, Without the `Start In` parameter set, my scheduled batch file would not run at all. (Windows 7) – Justin Skiles Apr 22 '14 at 13:03
  • 2
    This solution didn't work for me. The answer provided by @Arun Raja worked fine. – Cagy79 Dec 19 '14 at 10:02
  • Start in is what caused mine not to run also – user2865446 Feb 20 '15 at 07:29
  • 2
    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. – Aaron Jul 29 '15 at 17:57
  • 1
    Mine didn't work initially with this solution, and it worked with the one by @Arun Raja, but the second had drawbacks. I then noticed my file.bat had a "ECHO ON" line in it. I put it "OFF" and it worked with this solution. Weirdly, before this problem showed up, it had worked fine for more than a year. I'm wondering what changed to make it behave like that. Maybe some update to the OS? – azzurroverde Nov 11 '15 at 20:21
  • I was running WinRAR in my backup .BAT script and running under Task Scheduler created individual .RAR files for each file in the folder. Adding the Start In path fixed my problem. – D. Dubya Feb 14 '16 at 17:01
  • 12
    @DCaugs The `Start in` is the main reason it worked for me. – Gustavo Aug 30 '16 at 19:13
  • @Gustavo: Interesting - it's possible that was driven by the security context of the directory in my case. That environment is long gone, so I can't be certain. =) – DCaugs Aug 31 '16 at 12:16
  • This has been causing me an issue for the past 24 hours after reports that had been set and working for years suddenly and inexplicably stopped running overnight. All very bizarre but this solution has been the remedy to all of my pain! Thank you... – Mr Deans Nov 08 '16 at 10:01
  • 7
    "Do not put quotes around Start In" <-- I hope they should make this obvious to the user. – Thariq Nugrohotomo Jun 06 '17 at 02:23
  • I need to run the same task and send email also to distribution lists. how can we do that? Since, either we can start a program or send an email or display a message. Please suggest. – avidCoder Oct 14 '19 at 06:15
  • This worked for me but no window displaying the execution logs appeared. Is there a way to fix that? – Gustavo Feb 12 '20 at 15:14
  • This answer is old but is still very useful for task scheduler. My application was not a batch script and it solved my problem to get it running. – Ricardo Gonçalves Jul 25 '20 at 18:19
  • For me Start in was the problem. Thanks, worked like a charm! :) – Shreeya Patel Sep 15 '20 at 11:18
  • 1
    Step 4, `Start in:`, was the missing piece for me. – David Chopin Nov 30 '20 at 03:44
  • Wonderful! is the solution among the full privileges, and the run with highest privileges tick. – Higinio Fuentes Mar 02 '21 at 03:37
  • 1
    Step 4 was also not obvious. But that did help, thank you! :) – Mykhailo K. Mar 06 '21 at 00:25
  • `Start in:` was the missing cricial link here on a Windows 10 machine too! – elburro1887 Apr 15 '23 at 13:08
85

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)

Olivier Jacot-Descombes
  • 104,806
  • 13
  • 138
  • 188
Arun Raja
  • 1,554
  • 16
  • 26
  • 2
    I concur! none of the previous solutions worked for me on a Windows Server 2008. This answer did the trick for me! Thanks. – Cagy79 Dec 19 '14 at 10:01
  • 4
    I wish I could give you a +2000. I've been trying different approaches all day long and nothing worked well except your solution. I had to launch a batch file which in turn launches another batch file 10 times with different parameters. From the console everything worked fine but the Task Scheduler refused to open more than 4 processes at the same time. It was weird... With your technique all the 10 processes were launched. – Icarus Oct 23 '15 at 20:56
  • 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. – azzurroverde Nov 10 '15 at 04:23
  • u need to keep a mail notification at the end of the bat file completion to notify its status. thats one way. – Arun Raja Nov 14 '15 at 03:40
  • 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. – mheavers Dec 28 '15 at 16:05
  • 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 – Aidy J Nov 09 '16 at 10:02
  • The above solution didn't work for me on windows server 2019 – Pramod Jun 04 '19 at 06:46
  • Just so people know, you may need to change it to `/k` instead of `/c` to keep the command window "open" to complete its tasks, depending on what those tasks are, such as powershell calls, etc. You can then add `exit` at the end of your batch file to close it. This might help solve some people's issues. The command window will NOT show if you select "Run whether user is logged in or not". It will run in the background and you won't be able to see it on screen. – Ethan Allen Feb 27 '20 at 06:17
  • Also, Program should be `C:\Windows\System32\cmd.exe` – Ethan Allen Feb 27 '20 at 06:23
59

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)

micstr
  • 5,080
  • 8
  • 48
  • 76
24

Make sure "Start In " has NO QUOTES.

Jonathan
  • 6,741
  • 7
  • 52
  • 69
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

Jean-François Corbett
  • 37,420
  • 30
  • 139
  • 188
Ruben
  • 8,956
  • 14
  • 63
  • 102
  • 2
    Sorry to say, but this is a very poorly written answer. I would make sure the proper answer is selected as the accepted answer. – jwize Jan 01 '14 at 11:06
8

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
Rohit
  • 6,365
  • 14
  • 59
  • 90
7

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

Michael Kehoe
  • 79
  • 1
  • 1
  • 1
    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? – lessthanideal Jun 26 '15 at 16:52
  • 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. – Aaron Jul 29 '15 at 17:55
  • 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 – Tony Mar 26 '21 at 01:45
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.

Chriz
  • 572
  • 7
  • 14
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" 
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

Robb
  • 31
  • 1
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.

Vince
  • 147
  • 1
  • 2
2

I post the answer to this question here and here.

enter image description here

ToCarbajal
  • 420
  • 3
  • 6
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

sapitron
  • 11
  • 1
  • 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 ! – Youssef Oct 15 '22 at 13:56
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.

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

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.

C Jee
  • 1
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.

Ethan Allen
  • 14,425
  • 24
  • 101
  • 194
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!

Anton Makarov
  • 562
  • 3
  • 12