Run a batch file with Windows task scheduler

Windows 7Batch FileScheduled Tasks

Windows 7 Problem Overview


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?

Windows 7 Solutions


Solution 1 - Windows 7

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!

Solution 2 - Windows 7

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)

Solution 3 - Windows 7

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)

Solution 4 - Windows 7

Make sure "Start In " has NO QUOTES.

Solution 5 - Windows 7

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

Solution 6 - Windows 7

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

Solution 7 - Windows 7

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.

Solution 8 - Windows 7

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

Solution 9 - Windows 7

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" 

Solution 10 - Windows 7

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

Solution 11 - Windows 7

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.

Solution 12 - Windows 7

I post the answer to this question here and here.

enter image description here

Solution 13 - Windows 7

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.

Solution 14 - Windows 7

  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

Solution 15 - Windows 7

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

Solution 16 - Windows 7

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.

Solution 17 - Windows 7

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRubenView Question on Stackoverflow
Solution 1 - Windows 7GhaziView Answer on Stackoverflow
Solution 2 - Windows 7Arun RajaView Answer on Stackoverflow
Solution 3 - Windows 7micstrView Answer on Stackoverflow
Solution 4 - Windows 7JonathanView Answer on Stackoverflow
Solution 5 - Windows 7RubenView Answer on Stackoverflow
Solution 6 - Windows 7Michael KehoeView Answer on Stackoverflow
Solution 7 - Windows 7ChrizView Answer on Stackoverflow
Solution 8 - Windows 7RohitView Answer on Stackoverflow
Solution 9 - Windows 7Bruce MetelerkampView Answer on Stackoverflow
Solution 10 - Windows 7RobbView Answer on Stackoverflow
Solution 11 - Windows 7VinceView Answer on Stackoverflow
Solution 12 - Windows 7ToCarbajalView Answer on Stackoverflow
Solution 13 - Windows 7user6039542View Answer on Stackoverflow
Solution 14 - Windows 7Shahidul Islam MollaView Answer on Stackoverflow
Solution 15 - Windows 7sapitronView Answer on Stackoverflow
Solution 16 - Windows 7C JeeView Answer on Stackoverflow
Solution 17 - Windows 7Ethan AllenView Answer on Stackoverflow