185
votes

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?

17
Not sure if this question is offtopic but you might get better responses on serverfault.com for it.Hans Olsson
Thanks I'll also try to post it on serverfaultRuben
this can be usefull too: serverfault.com/questions/734035/…Ruben

17 Answers

336
votes

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!

64
votes

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)

49
votes

For those whose bat files are still not working in Windows 8+ 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 the Start In path to your batch file, even though it says optional
  2. use quotes, if you need to, in your Start a program > program/script entry i.e "C:\my scripts\runme.bat" ...
  3. BUT DON'T use quotes in your Start in field. (Crazy but true!)

This worked without any need to trigger a command prompt.

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

23
votes

Make sure "Start In " has NO QUOTES.

8
votes

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

7
votes

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

5
votes

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.

3
votes

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
votes

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

2
votes

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.

2
votes

I post the answer to this question here and here.

enter image description here

1
votes

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
votes
  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
votes

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

0
votes

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.

0
votes

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.

0
votes

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