Automatic Defragmentation

Defragmentation can be easily fully automated. Just click Settings > Preferences, open the Automatic defragmentation tab, select the disks you would like to defragment automatically and click OK.

By default the program performs automatic defragmentation once a day when the computer is idle. To adjust defragmentation schedule click Settings > Preferences, open the Automatic defragmentation tab and click Schedule. Alternatively, you can adjust the schedule directly in Windows Task Scheduler.

  • By default the automatic defragmentation will not be performed when the computer runs on batteries.
  • To prevent waste of time the program disables the following built-in task on Windows Vista and more recent Windows editions:
    Task Scheduler Library\Microsoft\Windows\Defrag\ScheduledDefrag.

Also it is possible to execute a custom script during the automatic defragmentation. Just click Settings > Preferences, open the Automatic defragmentation tab, select the Execute custom script option there and click OK. To adjust the script click Edit custom script or open the following file manually in a text editor: {installation folder}\tasks\auto-defrag-custom.cmd.

By default the program uses the following custom script:

@echo off
:: UltraDefrag - a powerful disk defragmenter for Windows.
:: auto-defrag-custom.cmd - custom script for automatic defragmentation.
:: Visit
:: for general information about the script syntax.
:: Refer to the Console chapter of the UltraDefrag Handbook for detailed
:: information about the `udefrag` command and environment variables
:: controlling its behaviour. You should have received the handbook
:: along with this program, if not, you can find it at the official
:: UltraDefrag website (
:: To use Unicode characters in filters edit this file in the Notepad++
:: editor and then save it in UTF-8 (without BOM) encoding.
:: Also Notepad++ features syntax highlighting which makes it much easier
:: to edit the file. The latest version of Notepad++ can be downloaded
:: for free from
:: Below is a sample script. It defragments system drive and heavily
:: fragmented content on all the connected non-removable drives.
:: Feel free to adjust it to make it more suitable for your needs,
:: replace it entirely or keep as is.
:: first of all, let's set UD_EX_FILTER to exclude all
:: the stuff which rarely benefits from defragmentation
:: exclude temporary content
set UD_EX_FILTER=*system volume information*;*temp*;*tmp*;*recycle*
set UD_EX_FILTER=%UD_EX_FILTER%;*dllcache*;*ServicePackFiles*;*.log
set UD_EX_FILTER=%UD_EX_FILTER%;*Windows.old*
:: exclude archives
set ARCHIVE_PATTERNS=*.7z;*.7z.*;*.arj;*.bkf;*.bz2;*.bzip2;*.cab;*.cpio;*.deb
set ARCHIVE_PATTERNS=%ARCHIVE_PATTERNS%;*.dmg;*.gz;*.gzip;*.lha;*.lzh;*.lzma
set ARCHIVE_PATTERNS=%ARCHIVE_PATTERNS%;*.rar;*.rpm;*.swm;*.tar;*.taz;*.tbz
set ARCHIVE_PATTERNS=%ARCHIVE_PATTERNS%;*.tbz2;*.tgz;*.tpz;*.txz;*.xar;*.xz
:: exclude multimedia content
set AUDIO_PATTERNS=*.aif;*.cda;*.flac;*.iff;*.kpl;*.m3u;*.m4a;*.mid
set AUDIO_PATTERNS=%AUDIO_PATTERNS%;*.mp3;*.mpa;*.ra;*.wav;*.wma
set VIDEO_PATTERNS=*.3g2;*.3gp;*.asf;*.asx;*.avi;*.flv;*.mov;*.mp4
set VIDEO_PATTERNS=%VIDEO_PATTERNS%;*.mpg;*.rm;*.srt;*.swf;*.vob;*.wmv
:: exclude virtual machines
set DISK_IMAGE_PATTERNS=*.fat;*.hdd;*.hfs;*.img;*.iso;*.ntfs;*.squashfs
set DISK_IMAGE_PATTERNS=%DISK_IMAGE_PATTERNS%;*.vdi;*.vhd;*.vmdk;*.wim
:: exclude big fragments which rarely benefit from defragmentation
:: if your system drive is an SSD uncomment the following
:: line to exclude slightly fragmented content as well
:: uncomment the following line to increase amount of debugging output
:: defragment system drive
set UD_LOG_FILE_PATH=%UD_INSTALL_DIR%\logs\autodefrag-system.log
udefrag --wait %SystemDrive%
:: defragment heavily fragmented content
:: on all the connected non-removable drives
set UD_LOG_FILE_PATH=%UD_INSTALL_DIR%\logs\autodefrag-fixed.log
udefrag --wait --all-fixed