Occasionally, you might need to schedule to run a batch file automatically in your Windows. In this article, I’ll share a tip on how to schedule a Batch file automatically using Task Scheduler.
Schedule a Batch File to run automatically in Windows 11/10
To schedule a Batch File to run automatically in Windows 11 and Windows 10, you will have to follow these steps:
- Create a Batch file
- Open Task Scheduler
- Create a Basic Task
- Open Task Scheduler Library
- Make Task runs with the highest privileges.
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.
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 would like to run.
Step 8: Finally, click on Finish to create the Task.
Now that we have created a Task, we must ensure it runs with the highest privilege. Since we have UAC settings, we have to make sure that it should not fail if it does not bypass the UAC settings when you run the file.
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. However, there can be drawbacks such as if the application you are trying to invoke needs a password. In that case, you cannot run it silently.
How do I run multiple batch files after one?
If you want to run batch files one after another, you can use the task scheduler and time them to run with the one-minute gap. The other way is to create a mother batch file, add a list of all bat files inside it, and let it execute one after the other.
How to add timeout or sleep in a Batch File?
You can add the following command along with other parameters. It will ensure user input is not considered, and there is no output for this.
timeout /t 30 /nobreak > NUL
How to run the batch files on Startup?
When setting up the task with the scheduler, you can run it as soon as you log into the PC. It can be delayed by a minute, but it will be executed. If you need to run it every few minutes, make sure to set it accordingly.
this is exactly what i was looking for. thx!
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
Thank you!
thank you so much))))
Does not work.
Followed instructions exactly
Getting error: “Windows cannot find ‘file.bat’.
The pathing is correct.
Hey Thankxxx a lot for sharing this idea…
Thanks!!! Great Help….
Thank you, it worked……….
on windows 8 it runs in background and is a pain in the butt to make run on foreground. Please help
thanks bro.
Thanks for the explanation, my batch file works now.
How to give the destination folder path for backup tasks
Exactly what I was looking for! Thank You!
Simply great!
this was helpful n clear, thanks for your help! :)
wooow it is cool
auto virus runer created
Very nice Tutorial. How to make it run several times a day on it’s on (Scheduled) and what is the Hidden for?
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!
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.
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.
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..!!
i am using UNC path for backup script to store on different server.The task runs without errors but output file is not created.
HOW WE CAN RUN BATCH FILE HOURLY ???
Go to task propeties… Triggers tab… there you will see option to schedule it on hourly basis
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
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
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!
It helped me alot..! thanx
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.
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
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
can i use this bat file in an other compurer
I’m having a similar problem. It seems that this doesn’t work well with environment variables and/or batch file variables.
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
My application has authentication so, is there any possibilities to proceed the password in task scheduler??