Wasn't sure if this was an unattended thing or an Application switches things so forgive me if I'm it's in the wrong place, "I'm new here" I looked through all the diskeeper threads and they're all about installing it, none seem to be about using it so here you go. WHY? Your custom install has completed, you've put on all your apps and deleted all the surplus windows dross, you've done your cleanup and your system is all ready to go. Except with all that messing, your drive is chewed up beyond belief. So the first thing you do is run diskeeper to defrag the thing. After every install. So why not do it automatically? THE LOGIC Diskeeper does two main type of defrag; - The standard one with the pretty display - which tidies up your files and folders and makes all the red bits go blue - The Boot time one which runs before windows has grabbed everything Ideally you want to do both, and ideally you want the boot one to go first. But the boot one runs at boot time and resets when it's done, so we need to mess about a bit. (If there's anyone there from executive software who knows a better way, please feel free to jump in anythime ) THE FLY IN THE OINTMENT Only one for now, the registry entry that diskeeper uses to call the boot time routine is stored in the "BootExecute" key in [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager] , this is a multi string key (REG_MULTI_SZ) and as this can't (as far as I know) contain expandable strings, the drive reference is absolute. So I have to fiddle it with multiple .reg files for now 'cos I haven't done a dynamic key generating thingy yet. THE METHOD Ok, this is my first working version so it might not be the best way to do a lot of stuff, but it definately works and I happy with that much. I do intend to tidy it up a little, but keep thinking of that expression "if it 'aint broke, don't fix it" It assumes you have installed diskeeper and will do a forced reset after your cleanup routine. 1. The Files In a folder (I use the usual \Install\Diskeeper), you have the following files; DEFRAGME.DAT - an empty file used by diskeeper FRAG1.CMD - The File you call from your normal install FRAG2.CMD - The File that handles the second part of the defrag FRAG1.REG - The Registry key used by FRAG1 FRAG2.REG - The Registry key used by FRAG2 FRAG_C.REG - Reg key with fixed drive reference to C: FRAG_D.REG - Reg key with fixed drive reference to D: etc. 2. Setting up Call FRAG1.CMD from your normal install routine after diskeeper is installed. FRAG1.CMD TITLE - Schedule Defrag - SET MYLOG="%UserProfile%\Desktop\Install.Log" SET INSTALL=%systemdrive%\Install ECHO ... Queuing a Boot time defragment of Drive %systemdrive% ... REM - First we copy the batch file and reg entry needed for stage 2 copy /Y %install%\Diskeeper\FRAG2.* %systemdrive%\ REM - We set an entry in the Run section of the registry to call stage 2 start /wait regedit /s %install%\Diskeeper\FRAG1.reg REM - Check if we have a drive specific Reg File and if so apply it IF EXIST "%INSTALL%\Diskeeper\Defrag_%systemdrive:~0,1%.reg" ( copy /Y %install%\Diskeeper\defragme.dat %systemdrive%\ start /wait regedit /s %INSTALL%\Diskeeper\Defrag_%systemdrive:~0,1%.reg ECHO Two Stage Boot time Defrag Queued ECHO %TIME% - - Two Stage Boot time Defrag Queued >>%MYLOG% ) ELSE ( ECHO Second Stage Defrag Queued ECHO %TIME% - - Second Stage Defrag Queued >>%MYLOG% ) ECHO.(NB: "%systemdrive:~0,1%" Returns the System Drive Letter without the colon so that it can be used to pick up the correct .reg file) FRAG1.REG Windows Registry Editor Version 5.00 ; Queue The Autorunning of the second stage Defrag ; (whether or not the First - boot stage will be done) ; ; this bit says "CMD /C "IF EXIST %systemdrive%\FRAG2.CMD CALL %systemdrive%\FRAG2.CMD" [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run] "Frag2"=hex(2):43,00,4d,00,44,00,20,00,2f,00,43,00,20,00,22,00,49,00,46,\ 00,20,00,45,00,58,00,49,00,53,00,54,00,20,00,25,00,73,00,79,00,73,00,74,00,\ 65,00,6d,00,64,00,72,00,69,00,76,00,65,00,25,00,5c,00,46,00,52,00,41,00,47,\ 00,32,00,2e,00,43,00,4d,00,44,00,20,00,43,00,41,00,4c,00,4c,00,20,00,25,00,\ 73,00,79,00,73,00,74,00,65,00,6d,00,64,00,72,00,69,00,76,00,65,00,25,00,5c,\ 00,46,00,52,00,41,00,47,00,32,00,2e,00,43,00,4d,00,44,00,22,00,00,00 I use Run because a RunOnce entry would be removed before it got chance to run. OK, so we've got the second part queued and that will run whether or not the first (boot time) stage is run. So onto that. DEFRAG_C.REG Windows Registry Editor Version 5.00 ; Call for diskeeper to do a boot time defrag... [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager] "BootExecute"=hex(7):61,00,75,00,74,00,6f,00,63,00,68,00,65,00,63,00,6b,00,20,\ 00,61,00,75,00,74,00,6f,00,63,00,68,00,6b,00,20,00,2a,00,00,00,41,00,55,00,\ 54,00,4f,00,4e,00,54,00,46,00,53,00,20,00,43,00,3a,00,20,00,50,00,41,00,47,\ 00,45,00,3d,00,4d,00,49,00,4e,00,20,00,44,00,49,00,52,00,53,00,3d,00,4d,00,\ 46,00,54,00,5a,00,20,00,4d,00,46,00,54,00,3d,00,4d,00,49,00,4e,00,20,00,00,\ 00,00,00What this is actually saying is autocheck autochk * AUTONTFS C: PAGE=MIN DIRS=MFTZ MFT=MIN The first line belongs to windows, the second to diskeeper This example is for drive C, to change it to use in "DEFRAG_D.REG", "DEFRAG_E.REG" etc. you need to change the drive letter reference (43) - 3rd line down, 15th Byte across (between 20 00 and 00 3a) - to the correct number; C = 43 D = 44 E = 45 etc. You can have as many as you like, FRAG1 will only use the correct one if it's there. 3. Second Stage The second stage command file (%SYSTEMDRIVE%\FRAG2.CMD) needs to check if the first stage (boot time) defrag has completed - remember "DEFRAGME.DAT"? Well Diskeeper deletes this once the boot time defrag has run. Also if there wasn't a valid .reg file for the system drive, and the first stage wasn't queued "DEFRAGME.DAT" Won't exist. Works both ways. DEFRAG2.CMD @ECHO OFF TITLE - Second Stage Defrag - SET MYLOG="%UserProfile%\Desktop\Install.Log" REM - Only do the full defrag if the boot one is not queued IF NOT EXIST %SYSTEMDRIVE%\defragme.dat ( ECHO %TIME% - Second Stage Defrag Started >>%MYLOG% ECHO - Second stage Defragmenting of %SYSTEMDRIVE% ECHO. ECHO There may be a short delay while we wait for the service to start ECHO. diskeeper %SYSTEMDRIVE:~0,1% start /wait regedit /s %systemdrive%\FRAG2.reg DEL /q /f %SYSTEMDRIVE%\FRAG2.reg ECHO %TIME% - Second Stage Defrag Finished >>%MYLOG% ) ELSE ( ECHO %TIME% - Second Stage Defrag Skipped >>%MYLOG% ECHO (First Stage not yet run) >>%MYLOG% ) IF NOT EXIST %SYSTEMDRIVE%\defragme.dat DEL /q /f %0 FRAG2.REG Windows Registry Editor Version 5.00 ; Remove the Run Command that called Frag2 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run] "Frag2"=-So what this does is waits until the file is gone, defrags the system drive, clears the registry entry and cleans up after itself. FRAG2.reg is the best place to activate any registry monitoring utils. Until now they would have got upset with all my fiddling so mine also has the following ; Activate Adwatch & Adaware ; NB: Adaware uses absolute References, but the version below uses expanding string ; reg keys to keep it drive independant. ; "%ProgramFiles%\Ad-aware 6\Ad-aware.exe" +c ; "%ProgramFiles%\Ad-aware 6\Ad-watch.exe" [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run] "Ad-aware"=hex(2):22,00,25,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,46,00,69,\ 00,6c,00,65,00,73,00,25,00,5c,00,41,00,64,00,2d,00,61,00,77,00,61,00,72,00,\ 65,00,20,00,36,00,5c,00,41,00,64,00,2d,00,61,00,77,00,61,00,72,00,65,00,2e,\ 00,65,00,78,00,65,00,22,00,20,00,2b,00,63,00,00,00 "Ad-watch"=hex(2):22,00,25,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,46,00,\ 69,00,6c,00,65,00,73,00,25,00,5c,00,41,00,64,00,2d,00,61,00,77,00,61,00,72,\ 00,65,00,20,00,36,00,5c,00,41,00,64,00,2d,00,77,00,61,00,74,00,63,00,68,00,\ 2e,00,65,00,78,00,65,00,22,00,00,00 Oh and remember not to delete FRAG2.CMD and FRAG2.REG during your normal cleanup, they are self cleaning Summary 1. The defrags are queued during normal installation the system reboots 2. First reboot, Diskeeper does a boot-time defrag and reboots 3. Windows loads normally when reaches the desktop calls diskeeper to do a full defrag 4. The registry is reset and the files removed. Your newly installed system has a defragged system drive. Well it worked for me, I hope someone else finds it useful.