Boot Time Defragmentation

To defragment files locked most of the time UltraDefrag can be launched inside of the Windows boot process. Being executed there UltraDefrag can defragment almost everything including paging and hibernation files.

To process selected disks at Windows boot click Action > Boot time defragmentation and select the action you would like to perform. The program will show a reboot confirmation dialog then. Click Reboot now to reboot the computer and perform the selected action at Windows boot immediately or click Reboot later to perform the action at the next system reboot.

Also it is possible to execute a custom script at Windows boot. Just click Action > Boot time defragmentation > Execute custom script. To adjust the script click Action > Boot time defragmentation > Edit custom script or open the following file manually in a text editor: %SystemRoot%\system32\ud-boot-time.cmd.

The following command line tools can also be used to control the boot time defragmentation: boot-on, boot-off and boot-config. The first one enables the boot time defragmentation, the second one disables it and the last one opens the custom script in Notepad.

The boot time interface is pretty straightforward. First of all it shows a prompt to hit any key to exit and then performs the selected action. The process can be easily aborted at any time using the Pause/Break key. Also it is possible to use the boot time interface interactively. Just hit the Escape key at any time and the program will show you the following prompt and wait for your input:

Interactive mode:
Type 'help' to list available commands.
#

The same interactive console will be shown on the screen after the custom script execution if the script does not include the exit command.

Available commands

:: or ; or #
Lines starting with one of these characters are treated as comments.
@
Lines starting with this character will be not shown on the screen.
boot-on
Turns the boot time defragmenter on for the next boots.
boot-off
Turns the boot time defragmenter off for the next boots.
call
Similar to the DOS command. Executes a script; if none is specified the main boot time script will be executed.
echo
Similar to the DOS command. Displays a message, an empty line, sets whether the commands will be shown on the screen or not or displays the current setting.
exit
Similar to the DOS command. Terminates UltraDefrag.
help
Lists all available commands.
hexview
Displays a file in a HEX viewer layout:
000000C0: 0a 00 3b 00 20 00 46 00 |   ;   F
000000C8: 72 00 61 00 67 00 6d 00 | r a g m
000000D0: 65 00 6e 00 74 00 65 00 | e n t e
history
Lists all manually entered commands. To cycle through them use the up/down arrow/cursor keys.
man
Lists or displays available manual pages.
pause
Pauses the script execution for the specified time interval (in milliseconds) or till a key is pressed if no duration is specified. For example, the command pause 1000 will pause execution for one second.
reboot
Reboots the computer.
set
Similar to the DOS command. Lists, sets and clears environment variables.
shutdown
Shuts the computer down.
type
Similar to the DOS command. Displays a file; if none is specified the main boot time script will be shown.
udefrag
The boot time equivalent of the Console Interface. Accepts the following command line switches: -l, -la, -a, -o, -q, --optimize-mft, --all, --all-fixed, --deep. To process single files or directories specify their absolute paths. If they include spaces enclose them by double quotes:

udefrag "C:\Documents and Settings\*" C:\WINDOWS\WindowsUpdate.log

All commands displaying long lists (help, hexview, history, man, set, type) are splitting them into pages in the interactive mode.

Environment variables

Environment variables can be used the same way as in Windows batch files.

Two special variables are supported: DATE for the current date in the format YYYY-MM-DD and TIME for the current time in the format HH-MM:

2012-02-14
12-48

Restrictions

Encrypted disks cannot be defragmented at boot time because the local security service is inactive on early stages of Windows boot.

UltraDefrag terminates immediately in Windows safe mode because it cannot display text on the screen there.

Custom scripts

By default the program uses the following custom script:

@echo off
::
:: UltraDefrag - a powerful disk defragmenter for Windows.
::
:: ud-boot-time-custom.cmd - custom script for boot time defragmentation.
::
:: Visit https://en.wikibooks.org/wiki/Windows_Batch_Scripting
:: for general information about the script syntax.
::
:: Refer to the Boot time defragmentation chapter of the UltraDefrag
:: Handbook for detailed information about the supported commands
:: and environment variables controlling their behaviour. You should
:: have received the handbook along with this program, if not, you can
:: find it at the official UltraDefrag website (https://ultradefrag.net/)
::
:: Please note that you have to save this file in Unicode
:: (UTF-16 / UCS-2 LE BOM) encoding.
::
:: For syntax highlighting the Notepad++ editor can be used.
:: The latest version of it can be downloaded for free from
:: http://www.notepad-plus-plus.org/
::
:: Below is a sample script. It defragments system files, including
:: registry, paging and hibernation files. Feel free to adjust it
:: to make it more suitable for your needs, replace it entirely
:: or keep as is.
:: turn the boot time defragmentation off for subsequent boots
boot-off
set UD_IN_FILTER=*windows*;*winnt*;*ntuser*;*pagefile.sys;*hiberfil.sys
set UD_EX_FILTER=*temp*;*tmp*;*dllcache*;*ServicePackFiles*;*.log;*Windows.old*
; exclude big fragments which rarely benefit from defragmentation
set UD_FRAGMENT_SIZE_THRESHOLD=20MB
; if your system drive is an SSD uncomment the following
; line to exclude slightly fragmented content as well
; set UD_FRAGMENTS_THRESHOLD=20
; uncomment the following line to increase amount of debugging output
; set UD_DBGPRINT_LEVEL=DETAILED
; uncomment the following line to save debugging information to a log file
; set UD_LOG_FILE_PATH=%UD_INSTALL_DIR%\logs\ud-boot-time.log
udefrag %SystemDrive%
exit