UltraDefrag

Silent installer for UltraDefrag - An Open Source Defragmenter, a disk defragmentation tool with boot time, console and GUI interface.

It uses the NSIS installer, see the UltraDefrag handbook for a list of supported installer command line switches.

Standard Edition V7

 <package id="Udefrag" name="Ultra Defragmenter" revision="%version%" reboot="false" priority="10"> 

        <variable name="version" value="7.0.0" />  
        <variable name="plateform" value="i386"  architecture="x86"/>
        <variable name="plateform" value="amd64" architecture="x64"/>

         <check type="uninstall" condition="exists" path="Ultra Defragmenter" value="%version%" />

    
	<install cmd='"%SOFTWARE%\UltraDefrag\ultradefrag-%version%.bin.%plateform%.exe " /S /NCRC' />
	<install timeout="15" cmd='%ComSpec% /C "%SystemRoot%\system32\bootexctrl.exe" /r defrag_native' />

	<downgrade include='install' />

	<upgrade include='install' />

	<remove timeout="300" cmd='%ComSpec% /c "%PROGRAMFILES%\UltraDefrag\uninstall.exe" /S /NCRC' /> 
	<remove timeout="15" cmd='%ComSpec% /C "%SystemRoot%\system32\bootexctrl.exe" /u defrag_native' />
	<remove timeout="60" cmd='%ComSpec% /c if exist "%SystemRoot%\UltraDefrag" rmdir /s /q "%SystemRoot%\UltraDefrag"' />
	<remove timeout="60" cmd='%ComSpec% /c if exist "%SystemRoot%\system32\ud-boot-time.cmd" del /f /q "%SystemRoot%\system32\ud-boot-time.cmd"' />
	<remove timeout="60" cmd='%ComSpec% /c if exist "%SystemRoot%\system32\udefrag-gui.cmd" del /f /q "%SystemRoot%\system32\udefrag-gui.cmd"' />
	<remove cmd='ping -n 20 127.0.0.1' />
  </package>


Micro Edition (Console Version)

This installs the appropriate version based on the Windows architecture.

<package id="UltraDefrag" name="Ultra Defragmenter" revision="%PKG_VERSION%" reboot="false" priority="10">

    <variable name="PKG_VERSION"       value="5.1.1" />
    <variable name="PKG_ARCHITECTURE"  value="%PROCESSOR_ARCHITECTURE%"/>
    <variable name="PKG_ARCHITECTURE"  value="i386" architecture="x86"/>
    <variable name="PKG_SOURCE"        value="%SOFTWARE%\UltraDefrag\ultradefrag-%PKG_VERSION%.bin.%PKG_ARCHITECTURE%.exe"/>
    <variable name="PKG_DESTINATION"   value="%ProgramFiles%\UltraDefrag"/>
    <variable name="PKG_REMOVE_SWITCH" value="/S _?=%PKG_DESTINATION%"/>

    <!-- install the micro edition -->
    <variable name="PKG_INSTALL_SWITCH" value='/S /MICRO=1' />

    <check type="uninstall" condition="versiongreaterorequal" path="Ultra Defragmenter" value="%PKG_VERSION%" />

    <install cmd='"%PKG_SOURCE%" %PKG_INSTALL_SWITCH% /D=%PKG_DESTINATION%' />

    <upgrade   include="install" />
    <downgrade include="install" />

    <remove cmd='"%PKG_DESTINATION%\uninstall.exe" %PKG_REMOVE_SWITCH%' />
    <remove cmd='%ComSpec% /C if exist "%PKG_DESTINATION%\uninstall.exe" del /f /q "%PKG_DESTINATION%\uninstall.exe"' />
    <remove cmd='%ComSpec% /C if exist "%PKG_DESTINATION%" rmdir /q /s "%PKG_DESTINATION%"' />
</package>


Standard Edition (GUI Version)

Set the default language with the /LANG installer command line switch depending on the system language.

<package id="UltraDefrag" name="Ultra Defragmenter" revision="%PKG_VERSION%" reboot="false" priority="10">

    <variable name="PKG_VERSION"       value="5.1.1" />
    <variable name="PKG_ARCHITECTURE"  value="%PROCESSOR_ARCHITECTURE%"/>
    <variable name="PKG_ARCHITECTURE"  value="i386" architecture="x86"/>
    <variable name="PKG_SOURCE"        value="%SOFTWARE%\UltraDefrag\ultradefrag-%PKG_VERSION%.bin.%PKG_ARCHITECTURE%.exe"/>
    <variable name="PKG_DESTINATION"   value="%ProgramFiles%\UltraDefrag"/>
    <variable name="PKG_REMOVE_SWITCH" value="/S _?=%PKG_DESTINATION%"/>

    <!-- default language is English -->
    <variable name="PKG_LANG" value="English (US)"/>

    <!-- overwrite default language for German systems -->
    <variable name="PKG_LANG" value="German" lcidOS="407,c07,1407,1007,807"/>

    <!-- install everything -->
    <variable name="PKG_INSTALL_SWITCH" value='/S /LANG="%PKG_LANG%" /FULL=1' />

    <!-- install only start menu icon for Windows 7 and above -->
    <variable name="PKG_INSTALL_SWITCH" value='%PKG_INSTALL_SWITCH% /ICONS=0 /STARTMENUICON=1' os="6\.[1-9]\.\d{4}"/>

    <check type="uninstall" condition="versiongreaterorequal" path="Ultra Defragmenter" value="%PKG_VERSION%" />

    <install cmd='"%PKG_SOURCE%" %PKG_INSTALL_SWITCH% /D=%PKG_DESTINATION%' />

    <upgrade   include="install" />
    <downgrade include="install" />

    <remove cmd='"%PKG_DESTINATION%\uninstall.exe" %PKG_REMOVE_SWITCH%' />
    <remove cmd='%ComSpec% /C if exist "%PKG_DESTINATION%\uninstall.exe" del /f /q "%PKG_DESTINATION%\uninstall.exe"' />
    <remove cmd='%ComSpec% /C if exist "%PKG_DESTINATION%" rmdir /q /s "%PKG_DESTINATION%"' />
</package>


Make UltraDefrag the default defragmenter

This is only valid if you have installed the GUI interface.


Place this as the last install command:

<install cmd='reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\DefragPath" /ve /t REG_EXPAND_SZ /d "%PKG_DESTINATION%\ultradefrag.exe" /f' />


Place this as the first remove command:

<remove cmd='rundll32.exe advpack.dll,LaunchINFSectionEx "%SystemRoot%\inf\dfrg.inf",,,4' />


Enable boot time processing after WPKG changed something

It is not recommended to defragment a disk very often, since this will heavily reduce the lifetime of the disk.

The package revision is the date of the last change in the format yyyy.mm.dd, which allows keeping track of the package changes too.

<package id="UltraDefragEnable" name="Ultra Defragmenter Enable Boot Scan" revision="2012.11.11" reboot="false" execute="changed">
    <depends package-id="UltraDefrag"/>

    <install cmd='%ComSpec% /C "%SystemRoot%\system32\bootexctrl.exe" /r defrag_native' />
    <remove cmd='%ComSpec% /C if exist "%SystemRoot%\system32\bootexctrl.exe" "%SystemRoot%\system32\bootexctrl.exe" /u defrag_native' />
</package>


It is recommended to use a boot time script that turns off boot time processing when finished.

@echo off
;--------------------------------------------------------------------
;                UltraDefrag Boot Time Shell Script
;--------------------------------------------------------------------
; !!! NOTE: THIS FILE MUST BE SAVED IN UNICODE (UTF-16) ENCODING !!!
;--------------------------------------------------------------------

; set processing time limit to one hour
set UD_TIME_LIMIT=1h

; quick optimize the system drive
udefrag %SystemDrive% -q

; disable boot time scan
boot-off

; terminate the execution
exit


Deploy custom configuration

There is a general configuration deployed and two examples show how to deploy based on computer name or operating system version.

The package revision is the date of the last change in the format yyyy.mm.dd, which allows keeping track of the package changes too.

<package id="UltraDefragConfig" name="Ultra Defragmenter Config" revision="2012.11.11" reboot="false" priority="10">
    <depends package-id="UltraDefrag"/>

    <check type="file" condition="sizeequals" path="%SystemRoot%\system32\ud-boot-time.cmd" value="2180">
        <condition>
            <check type="logical" condition="not"/>
                <check type="host" condition="hostname" value="SATELLITE"/>
            </check>
        </condition>
    </check>
    <check type="file" condition="sizeequals" path="%SystemRoot%\system32\ud-boot-time.cmd" value="2588"  hostname="SATELLITE" />

    <check type="file" condition="sizeequals" path="%UD_INSTALL_DIR%\options\guiopts.lua"   value="13987">
        <condition>
            <check type="logical" condition="not"/>
                <check type="host" condition="os" value="5\.\d\.\d{4}"/>
            </check>
        </condition>
    </check>
    <check type="file" condition="sizeequals" path="%UD_INSTALL_DIR%\options\guiopts.lua"   value="17206" os="5\.\d\.\d{4}" />

    <!-- general configuration -->
    <install cmd='%ComSpec% /C copy /b /v /y "%SOFTWARE%\UltraDefrag\ud-boot-time.cmd" "%SystemRoot%\system32\ud-boot-time.cmd" &gt;"%TMP%\UltraDefrag.log"' />
    <install cmd='%ComSpec% /C copy /b /v /y "%SOFTWARE%\UltraDefrag\guiopts.lua" "%UD_INSTALL_DIR%\options\guiopts.lua" &gt;&gt;"%TMP%\UltraDefrag.log"' />

    <!-- configuration applied via computer name -->
    <install cmd='%ComSpec% /C copy /b /v /y "%SOFTWARE%\UltraDefrag\ud-boot-time_%COMPUTERNAME%.cmd" "%SystemRoot%\system32\ud-boot-time.cmd" &gt;&gt;"%TMP%\UltraDefrag.log"' >
        <condition>
            <check type="file" condition="exists" path="%SOFTWARE%\UltraDefrag\ud-boot-time_%COMPUTERNAME%.cmd"/>
        </condition>
    </install>

    <!-- configuration applied via operating system version -->
    <install cmd='%ComSpec% /C copy /b /v /y "%SOFTWARE%\UltraDefrag\guiopts_WinNT5x.lua" "%UD_INSTALL_DIR%\options\guiopts.lua" &gt;&gt;"%TMP%\UltraDefrag.log"' >
        <condition>
            <check type="host" condition="os" value="5\.\d\.\d{4}"/>
        </condition>
    </install>

    <upgrade   include="install" />
    <downgrade include="install" />

    <remove cmd='%ComSpec% /c if exist "%SystemRoot%\system32\ud-boot-time.cmd" del /f /q "%SystemRoot%\system32\ud-boot-time.cmd"' />
    <remove cmd='%ComSpec% /c if exist "%UD_INSTALL_DIR%\options\guiopts.lua" del /f /q "%UD_INSTALL_DIR%\options\guiopts.lua"' />
</package>