Windows 11 and Windows 10 come with a basic defragmentation tool. If your PC is equipped with an SSD, you don’t need to defrag it; however, you should take care of defragmenting at least once a week if you are using HDD. Windows default defragment tool is not so powerful and does not feature advanced options, such as it can not defrag multiple drives at once. If you are looking for an advanced and free defragmentation tool, you can opt for Puran Defrag, IObit Smart Defrag, DiskTuna, or UltraDefrag. However, these apps are old but work well with Windows 11/10.
Although you can not include all the features offered by third-party freeware tools by tweaking registry or other methods, it is possible to make a batch file to run automatic drive optimizations regularly by default. If you would like to defrag a single hard drive or multiple hard drives, you can defrag your hard drive by making a batch file. Once you are ready with a batch file, just run it with elevated rights to defragment your HDD. Isn’t it easy?
How to Defragment Hard Drive using Batch file on Windows 11/10?
By default, Windows 11/10 runs automatic drive optimizations regularly. However, if your PC is busy, Windows may skip the defragmentation process resulting in slow performance. To get the best from your computer, you should defrag HDD regularly. Doing defragmentation manually on every drive is a time-consuming task. You have multiple drives to defrag; you might prefer to create a batch file to defrag it. Once the batch file is ready, just run them with administrative privileges. For that, you need to do the following:-
Step 1. Bring up the Run dialog box by pressing
Step 2. In the Run box, type the following and hit
Step 3. Assume you have five drives with letters No C, D, E, F, and G. Copy and paste the following in the notepad:-
@echo off defrag.exe C: -f defrag.exe D: -f defrag.exe E: -f defrag.exe F: -f defrag.exe G: -f
If on your PC drives letters are different than our example, you need to edit it according.
Step 4. Now, on the notepad file, click on the
Step 5. On the Save As dialog, select the file’s location where you would like to save this batch file. In the “File name” box, type defragment.bat or defragment.cmd. From the “Save as type” drop-down menu, select the “All Files” option. Once done, click on the
Step 6. To defragment all the available drives at once, right-click on the defragment.bat file that you have created using the above steps, and select
That’s all. If you want to run this batch file automatically, it is also possible to set it on Windows 11/10.
How to schedule a Batch File to run automatically in Windows 11/10?
Step 1. Press the
Step 2. In the available search results, click on the
Step 3. On the Task Scheduler window, click on the
Step 4. Under Create Basic Task Wizard, type in the name you would like and then click the
Step 5. From the Trigger, select the option you like and then click on the
I chose Weekly and then clicked the
Step 6. Select any weekday and time on which you want to execute that batch file, and then click on the
Step 7. Now, select
Step 8. On the upcoming window, click on the
Step 9. Finally, click on the
Using the same method, you can create scheduled tasks for any other batch file or an application on your Windows 11/10/8/7 PC.