Home:ALL Converter>Run a batch file with Windows task scheduler

Run a batch file with Windows task scheduler

Ask Time:2010-12-14T17:36:13         Author:Ruben

Json Formatter

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?

Author:Ruben,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/4437701/run-a-batch-file-with-windows-task-scheduler
Jonathan :

Make sure \"Start In \" has NO QUOTES.",
2014-06-19T16:21:29
user6039542 :

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.\nAlso 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.\nOnce 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.",
2016-03-09T13:01:11
Ruben :

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:\n\n\nCheck the account parameters of your scheduled task and make sure they are set to run whether or not someone is logged into the machine\ncheck run with most privileges/rights\nMake sure you go to the full path first: cd C:\\inetpub\\wwwroot\\infoweb\\factuur\\cron\nDon't use double quotes in your batch files (don't know why but seems to help)\nBe super admin, enter 'Net user administrator /active:yes' in command prompt, log out and log in as the super admin, so UAC is off\n",
2010-12-14T10:29:06
Shahidul Islam Molla :

\nDon't use double quotes in your cmd/batch file\nMake sure you go to the full path start in (optional):\nC:\\Necessary_file\\Reqular_task\\QDE\\cmd_practice\\\n\n\n",
2018-04-06T10:40:35
Michael Kehoe :

Make sure \"Start In\" does NOT end with a BACKSLASH.",
2015-06-26T16:41:24
C Jee :

Try run the task with high privileges.\n\nput a \\ at the end of path in \"start in folder\" such as c:\\temp\\\n\nI do not know why , but this works for me sometimes.",
2016-03-29T23:18:58
Rohit :

\n\n\n\n\n\nMy script was to pull latest code from master and publish a new branch\ncd D:\\dev\\repo\ngit checkout master\ngit pull\ngit branch -D my-branch\ngit push origin --delete my-branch\ngit checkout -b my-branch\ngit push -u origin my-branch\nexit\n",
2021-08-06T00:25:41
Chriz :

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.",
2016-05-10T12:25:32
Bruce Metelerkamp :

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.\n\nFrom 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!\n\nThis is the method in case its not clear which worked\n\nAction: start a program\nProgram/script : cmd\n (doesn't need the .exe bit!)\nAdd arguments:\n /c start \"\" \"E:\\Django-1.4.1\\setup.bat\" \n",
2015-09-22T08:05:31
Robb :

I messed with this for several hours and tried many different suggestions.\n\nI finally got it to work by doing the following:\n\n\n \n Action: Start a program\n \n Program/Script: C:\\scriptdir\\script.bat\n \n Add arguments (optional) script.bat\n \n Start in (optional): c:\\scriptdir\n \n run only when user logged in\n \n run with highest privileges \n \n configure for: Windows Vista, Windows Server 2008\n \n",
2016-05-24T21:44:58
Ghazi :

I faced the same problem, but I found another solution without having to modify my batch script.\n\nThe only thing that I missed out is at the 'Action' settings - \"Start in (Optional)\" option.\n\nGo the task properties --> Action tab --> Edit --> Fill up as below:\n\n\nAction: Start a program\nProgram/script: path to your batch script e.g. C:\\Users\\beruk\\bodo.bat\nAdd arguments (optional): <if necessary - depending on your script>\nStart in (optional): Put the full path to your batch script location e.g. C:\\Users\\beruk\\(Do not put quotes around Start In)\n\n\nThen Click OK\n\nIt works for me. Good Luck!",
2012-11-01T08:54:01
Vince :

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.\n\nIn 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.",
2016-07-11T12:33:14
Arun Raja :

None of the above method worked. I tried it this way as said it in a tutorial and it worked.\n\nAction:\n\nStart a program \n\n\nProgram/script:\n\ncmd\n\n\nAdd arguments:\n\n/c start \"\" \"E:\\Django-1.4.1\\setup.bat\"\n\n\nWorked for me on Win7 Pro. You must have an account with a password (blank passwords are no good)",
2014-11-21T06:30:38
ToCarbajal :

I post the answer to this question here and here.\n\n",
2019-11-27T22:53:40
micstr :

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:\n\nUnder Actions, Choose "Create BASIC task", not "Create Task"\n\nThat did it for me, plus the other issues not to forget:\n\nUse 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)...\nUse 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!)\n\nThis worked without any need to trigger a command prompt. And it is the quickest and simplest method.\n(Sorry my rep is too low to add my Basic Task tip to Ghazi's comments)",
2015-03-16T04:27:45
sapitron :

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:\n-Run only when user is logged on\n-Run with highest privileges.\nAll other variations failed. It's infuriating all the time wasted on this, but at least it works.\nOS: WINDOWS 8 CORE (BASIC) VERSION",
2015-08-23T18:07:44
yy