How to schedule a Batch File to run automatically in Windows 10/8/7

There are occasions where you might need to schedule to run a batch file automatically in your Windows. In this article I’ll suggest a tip on how to schedule a Batch file automatically using Task Scheduler.

Schedule a Batch File to run automatically

Step 1: Create a batch file you wish to run and place it under a folder where you have enough permissions. For example under C drive.

Step 2: Click on Start and under search, type in Task and click open Task Scheduler.

Step 3: Select Create Basic Task from the Action pane on the right of the window.

schedule a Batch File to run automatically

Step 4: Under Create Basic Task, type in the name you like and click Next.

Step 5: From the Trigger select the option you like and click Next.

I chose Daily and clicked Next, which brought me to this screen.

Step 6: Then click on Start a Program and click Next.

Step 7: Now click on Browser and select the batch file you like to run.

Step 8: Finally, click on Finish to create the Task.

Now that we have created a Task, we have to make sure it runs with the highest privilege. Since we have UAC settings we have to make sure that when you run the file it should not fail if it does not bypass the UAC settings.

So click on Task Scheduler Library.

Then double click on the Task you just created.

Step 8: Click on Run with Highest privilege then click OK.

Congratulations!  You have successfully created a Scheduled Task to automate a batch file.

Posted by on , in Category Windows with Tags
Shyam aka “Captain Jack” is a Microsoft MVP alumnus and a Windows Enthusiast with an interest in Advanced Windows troubleshooting. Suggestions made and opinions expressed by him here are his personal one's and not of his current employers. He blogs at captaindbg.com.

35 Comments

  1. this is exactly what i was looking for. thx!

  2. Onlypq

    Hi, not sure if you can help; My batch file is kicking of a powershell script, it starts the script then it hangs.
    Do you know what could be the problem

  3. Guest

    Thank you!

  4. Maryia30b

    thank you so much))))

  5. Oliverofthenight

    Does not work.
    Followed instructions exactly
    Getting error: “Windows cannot find ‘file.bat’.
    The pathing is correct.

  6. Ashok Sahu

    Hey Thankxxx a lot for sharing this idea…

  7. Afdsa

    Thanks!!! Great Help….

  8. Arun

    Thank you, it worked……….

  9. alex

    on windows 8 it runs in background and is a pain in the butt to make run on foreground. Please help

  10. Mahesh Kumar A

    thanks bro.

  11. LightnLar

    Thanks for the explanation, my batch file works now.

  12. rohitbindal

    How to give the destination folder path for backup tasks

  13. KCR

    Exactly what I was looking for! Thank You!

  14. Andrei

    Simply great!

  15. Mostafa Amine

    this was helpful n clear, thanks for your help! 🙂

  16. luuz

    wooow it is cool
    auto virus runer created

  17. Jake Roberts

    Very nice Tutorial. How to make it run several times a day on it’s on (Scheduled) and what is the Hidden for?

  18. Lilian

    can not recognize the shared drive when i was trying to export a file. if I double click the .bat file, it works, but did not work through task schedule. Any help will be much appreciated!

  19. Roberto Lenti

    Don’t work, the task won’t start even if i stat it manually on task scheduler.
    Starting the bat on dos prompt run perfectly.

  20. Roberto Lenti

    Don’t work!
    The task in log result as started but i don’t see the effects.
    If i run the batch manualli it’s work perfectly.

  21. Karthik Munukuntla

    The scheduler runs every night.. and it currently updates the created file. I want to create a new file every time the scheduler is run… Could you help me with this..!!

  22. Guest

    i am using UNC path for backup script to store on different server.The task runs without errors but output file is not created.

  23. smoothblood

    HOW WE CAN RUN BATCH FILE HOURLY ???

  24. Manish SHIRODE

    Go to task propeties… Triggers tab… there you will see option to schedule it on hourly basis

  25. Thanks Captain, 8.1 was hijacking my grub. Now, I’ll just run a script at start up. There’s three days I’ll never get back.
    Gary

  26. DJ

    Hi, I created a task to execute a batch file which has sqlcmd to execute a stored proc. If I run the batch file manually, it works as expected. According to the history, The task starts at scheduled time and completes successfully. The stored procedure is not run. Can you please let me know how to fix this.

    E:Program FilesMicrosoft SQL Server110ToolsBinnSQLCMD.EXE -E -S %DBSERVER% -d %DATABASE% -Q “SET NOCOUNT ON; exec my_stored_proc” -o %NOUTQ%Reportsmy_stored_proc_report.txt -s” ” -W -k1 -u

  27. Dharanitharan

    Hi, Is it possible to schedule the batch file to run multiple times on a single day? If yes, can you please provide me the steps to schedule it multiple times on a single day.

    Thanks in advance!

  28. abc

    It helped me alot..! thanx

  29. Frank Van Der Mast

    not sure if still relevant but here is an example of a backup task put into a .BAT file:

    ROBOCOPY D:DATA E:BACKUPS /E /ZB /J /W:600 /MIR /XO /ETA
    PAUSE

    (D is the source location for the original files and E is the destination location)
    This command will copy all files from D:DATA to E:BACKUPS preserving (sub)folder structure and it will only copy&replace modified files.. so it won’t copy over if files haven’t been changed since last backup.

  30. Krishna

    Hi All,
    I’m facing a similar issue, I have written a VBScript to disable NIC and a batch script to execute this VBScript, the batch script need to run with admin privileges, so I’m opening CMD with admin privileges and executing the batch script, in turn the batch script will run the vbscript. Now, when I’m scheduling this batch script to run, the batch script is running properly, but NIC doesn’t get disabled, this clearly means, it is lacking admin rights on the VBScript file. Please guide me where I’m going wrong

  31. Pete_O

    I know this thread is quite old, but hopefully people are still seeing it.
    I have 9 batch files that move files from one directory to another drive and directory every night. This is triggered by using task scheduler as outlined above.

    Before I move the files, I have another batch file that goes in and counts the files in each directory.
    This is also run in task scheduler before any of the files are moved.

    When I run the counting batch file by itself, I get the correct amount of files in the %totalizer%
    When I run the counting batch using task scheduler, then the %totalizer% comes back 0 every time?

    Can anyone shed light as to where I screwed up? Batch File Below…, Thanks

    REM echo on
    setlocal

    echo dd = %date:~7,2%
    echo hh = %time:~0,2%

    REM if %time:~0,2% NEQ 23 Goto Done

    net use O:
    net use M:

    O:

    set totalizer=0

    cd O:B4UPPER
    set count=0
    for %%f in (Dir *.DAD) do set /A count=count+1
    set /A count=count-1
    set /A totalizer=totalizer+count

    echo %count% files found
    echo %totalizer% total

    REM /c move /y “O:B4UPPER*.*” “M:B4UPPER”
    REM echo %count% files were found to transfer to M B4UPPER on %date:~0,3% >> “C:_CRecorderLogsB4UPPER Chart Recorder Logs.txt”

    TIMEOUT /T 1 /NOBREAK

    cd O:B4LOWER
    set count=0
    for %%f in (Dir *.DAD) do set /A count=count+1
    set /A count=count-1
    set /A totalizer=totalizer+count

    REM /c move /y “O:B4LOWER*.*” “M:B4LOWER”
    REM echo %count% files were found to transfer to M B4LOWER on %date:~0,3% >> “C:_CRecorderLogsB4LOWER Chart Recorder Logs.txt”

    echo %count% files found
    echo %totalizer% total

    TIMEOUT /T 1 /NOBREAK

    cd O:B4LEFT
    set count=0
    for %%f in (Dir *.DDS) do set /A count=count+1
    set /A count=count-1
    set /A totalizer=totalizer+count

    REM /c move /y “O:B4LEFT*.*” “M:B4LEFT”
    REM echo %count% files were found to transfer to M B4LEFT on %date:~0,3% >> “C:_CRecorderLogsB4LEFT Chart Recorder Logs.txt”

    echo %count% files found
    echo %totalizer% total

    TIMEOUT /T 1 /NOBREAK

    cd O:B4MIDDLE
    set count=0
    for %%f in (Dir *.DAD) do set /A count=count+1
    set /A count=count-1
    set /A totalizer=totalizer+count

    REM /c move /y “O:B4MIDDLE*.*” “M:B4MIDDLE”
    REM echo %count% files were found to transfer to M B4MIDDLE on %date:~0,3% >> “C:_CRecorderLogsB4MIDDLE Chart Recorder Logs.txt”

    echo %count% files found
    echo %totalizer% total

    TIMEOUT /T 1 /NOBREAK

    cd O:B4RIGHT
    set count=0
    for %%f in (Dir *.DAD) do set /A count=count+1
    set /A count=count-1
    set /A totalizer=totalizer+count

    REM /c move /y “O:B4RIGHT*.*” “M:B4RIGHT”
    REM echo %count% files were found to transfer to M B4RIGHT on %date:~0,3% >> “C:_CRecorderLogsB4RIGHT Chart Recorder Logs.txt”

    echo %count% files found
    echo %totalizer% total

    TIMEOUT /T 1 /NOBREAK

    cd O:B5LEFT
    set count=0
    for %%f in (Dir *.DAD) do set /A count=count+1
    set /A count=count-1
    set /A totalizer=totalizer+count

    REM /c move /y “O:B5LEFT*.*” “M:B5LEFT”
    REM echo %count% files were found to transfer to M B5LEFT on %date:~0,3% >> “C:_CRecorderLogsB5LEFT Chart Recorder Logs.txt”

    echo %count% files found
    echo %totalizer% total

    TIMEOUT /T 1 /NOBREAK

    cd O:B5MIDDLE
    set count=0
    for %%f in (Dir *.DAD) do set /A count=count+1
    set /A count=count-1
    set /A totalizer=totalizer+count

    REM /c move /y “O:B5MIDDLE*.*” “M:B5MIDDLE”
    REM echo %count% files were found to transfer to M B5MIDDLE on %date:~0,3% >> “C:_CRecorderLogsB5MIDDLE Chart Recorder Logs.txt”

    echo %count% files found
    echo %totalizer% total

    TIMEOUT /T 1 /NOBREAK

    cd O:B5RIGHT
    set count=0
    for %%f in (Dir *.DDS) do set /A count=count+1
    set /A count=count-1
    set /A totalizer=totalizer+count

    REM /c move /y “O:B5RIGHT*.*” “M:B5RIGHT”
    REM echo %count% files were found to transfer to M B5RIGHT on %date:~0,3% >> “C:_CRecorderLogsB5RIGHT Chart Recorder Logs.txt”

    echo %count% files found
    echo %totalizer% total

    TIMEOUT /T 1 /NOBREAK

    cd O:B5WDWRD
    set count=0
    for %%f in (Dir *.DDS) do set /A count=count+1
    set /A count=count-1
    set /A totalizer=totalizer+count

    REM /c move /y “O:B5WDWRD*.*” “M:B5WDWRD”
    REM echo %count% files were found to transfer to M B5WDWRD on %date:~0,3% >> “C:_CRecorderLogsB5WDWRD Chart Recorder Logs.txt”

    echo %count% files found
    echo %totalizer% total

    TIMEOUT /T 1 /NOBREAK

    C:
    cd C:_CRecorderLogs

    Echo %totalizer% files for transfer
    REM Pause

    REM to add email reciprients use no spaces and add a comma between each email address
    REM Line below builds the sting that goes into the email message body.

    Echo %totalizer% Files out of 216 were transfered last night. If you don’t get this email daily, there could be a problem. Moving the files are 9 seperate Task Manager tasks. The batch file to count all of the recorder logging is in the datetime.bat file located in C:_CRecorderLogs directory. > Data.Txt

    if %totalizer% EQU 216 c:bmailbmail -s citysrv11.coffeyville.local -p 25 -t polsen@coffeyville.com -f Recorders@Coffeyville.com -h -a “Chart Recorder Transfer Successful.” -m Data.Txt -c

    if %totalizer% LSS 216 c:bmailbmail -s citysrv11.coffeyville.local -p 25 -t polsen@coffeyville.com -f Recorders@Coffeyville.com -h -a “Chart Recorders Alert LESS” -m Data.Txt -c

    if %totalizer% GTR 216 c:bmailbmail -s citysrv11.coffeyville.local -p 25 -t polsen@coffeyville.com -f Recorders@Coffeyville.com -h -a “Chart Recorders Alert MORE” -m Data.Txt -c

    TIMEOUT /T 1 /NOBREAK

    REM Line below appends to the ChartRecorderLog.txt file daily

    echo Moves Completed on %date% at %time% with %totalizer% files moved of a possible 216 files >> “C:_CRecorderLogsChartRecorderLog.txt”

    TIMEOUT /T 1 /NOBREAK

    REM Line below opens notepad.exe with the daily log file.
    Start “” “C:_CRecorderLogsChartRecorderLog.txt”

    endlocal

    :Done

    :End

  32. Gevorg

    can i use this bat file in an other compurer

  33. teckel

    I’m having a similar problem. It seems that this doesn’t work well with environment variables and/or batch file variables.

  34. Eenie-Meanie

    I think .bat files need a double quote when starting the exe. I would also write in a log command to output the program errors

  35. Pavihran

    My application has authentication so, is there any possibilities to proceed the password in task scheduler??

Leave a Reply

Your email address will not be published. Required fields are marked *


5 + 2 =