Jump to content

Post Cleanup Automatic Defrag (Diskeeper)


Marl64

Recommended Posts

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" :huh:

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 :lol:)

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. :no:

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,00

What 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 :lol:

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.

Link to comment
Share on other sites


GOOOOOD...

i'd read some thread that generate 5k x 5k folders and each folder has 10k empty files, these folders and files are used to increase the MFT size. after deleting all these folders and files, the MFT size remains, then invoke the defragmenter, and he said you don't need any defragmenter anymore(for NTFS).

i can't remember where the thread was, the .cmd script was lost, maybe rewrite a .cmd script before your guide will be a good idea, worth a try.

Link to comment
Share on other sites

Here is a regtweak for MFT:

; MasterFileTable Sizing - 1=Default 2=Medium 3=Larger 4=Maximun
; ======================
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem]
"NtfsMftZoneReservation"=dword:00000001

Apparently 1 is 12.5%, 2 is 25%, 3 is 37.5% & 4 is 50%.

May be useful.

:)

Link to comment
Share on other sites

  • 1 month later...

from cleanup.cmd:

ECHO.
CALL %systemdrive%\install2\Applications\Diskeeper\FRAG1.CMD

i made a install2 file in $OEM$\$1 with the files

the Boot optimization in Diskeeper is better i think

btw i use now diskeeper 9 and it doesend seam to work any more :no:

so back to v8

edit: i did modi. the files so if you want you can download them

edit2: works now with v9 i ad this in FRAG2.CMD:

"%systemdrive%\Program Files\Executive Software\Diskeeper\DkService.exe"

install2.rar

Link to comment
Share on other sites

Did you modify the files to work with Diskeeper 9?

i did modify them to work from install2

for disk. v9: the cmd calls diskeeper

the file name's are the same and now the funny part

some times it works and some time's it dont

error mess. : cant start diskeeper service [in v9]

Link to comment
Share on other sites

What do these commands do?

copy /Y %Install2%\Applications\Diskeeper\FWALL.reg %systemdrive%\
ECHO.
copy /Y %Install2%\Applications\Diskeeper\enable SCenter.reg %systemdrive%\

I see no FWALL.reg or SCenter.reg in the file you have posted. Also, Why do you use Install2\applications? Is this where you install your files from from RunOnceEX, or are you copying files here, to prevent Cleanup.cmd from deleting the files?

Link to comment
Share on other sites

What do these commands do?

copy /Y %Install2%\Applications\Diskeeper\FWALL.reg %systemdrive%\
ECHO.
copy /Y %Install2%\Applications\Diskeeper\enable SCenter.reg %systemdrive%\

I see no FWALL.reg or SCenter.reg in the file you have posted. Also, Why do you use Install2\applications? Is this where you install your files from from RunOnceEX, or are you copying files here, to prevent Cleanup.cmd from deleting the files?

... you can delete that it was to enabele the firewall again

i use install2 because cleanup cmd delete's the install folder

and there is no way to use that folder for the diskeeper file's so i made install2

this way it defrags after the second logon

Link to comment
Share on other sites

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.

not sure if this is the same thing - the DOS command REG ADD can have variable paths. Just need to do a .CMD file and not a .REG file

Link to comment
Share on other sites

  • 3 weeks later...
Ideally you want to do both, and ideally you want the boot one to go first.
Executive says in their doc that a full defrag should be completed BEFORE boot-time (MFT) defrag, not the other way around.

Really? :o

I have always found the reverse works better.

Often the main defrag is hampered by directories dotted all over the place, directories it seems reluctant to do anything with - presumably because windows has got it's sticky hands on them :lol:

Running the boot one first gets these all into one place out of the way, giving the main one the rest of the disk to do with as it will.

:realmad: But the pig that annoys me is the reserved space, that Diskeeper will not touch and XP will not release.

I've got system restore off, trashcan to rock bottom and still there's this dirty great swathe of real estate that the builders won't go near.

"sorry mate, it can't go there, it's reserved see, by orders of da' management!" :lol:

post-70-1100741879_thumb.jpg

Link to comment
Share on other sites

  • 2 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...