Jump to content



Photo

Defrag Tool


  • Please log in to reply
6 replies to this topic

#1 chaos945

chaos945

    Seeker

  • Active Members
  • 34 posts

Posted 13 August 2004 - 03:52 AM

I wanted to make a script that uses a progress bar so I made this autodefragmenter tool. It will detect all FIXED drives, defragment them, then it will use the 'Process Idle Tasks' handle to arrange commonly used files to the beginning of the disk.

Anyone wanting to use the windows defrag icon it can be found in shell.32 as icon_81.ico

Please post any bugs you encounter.

/Revision
I've added the actual progress values rounded to the nearest whole number as they go by.

/Revision
New formula on progress bar is more accurate, determined by actual sizes of the drives, I tried to get it to sub-calculate values for each drive based on the time it takes to defrag x.x MB and the total size of the drive but it was more difficult than I expected, perhaps later I will add an Estimated Time Remaining: counter as well.

Plain Text         
HotKeySet( "{ESC}", "gotoExit" ) $var = DriveGetDrive( "FIXED" ) If NOT @error Then $totalspace = 0 $totalfree = 0 For $i = 1 to $var[0]     $free = DriveSpaceFree( $var[$i] )     $total = DriveSpaceTotal( $var[$i] )     $totalfree = $Free + $totalfree     $totalspace = $Total + $totalspace Next $totalused = $totalspace - $totalfree ProgressOn ( "AutoDefrag v0.4", "", "0%", -1, -1, 16 ) WinSetOnTop ( "AutoDefrag", "", 0 ) $usedCur = 0         For $i = 1 to $var[0]                 If $i = 1 Then             $CurrPer = 0         Else                        $used = ( DriveSpaceTotal( $var[$i-1] ) - DriveSpaceFree( $var[$i-1] ) )             $usedCur = $used + $usedCur             $currPer = ( $usedCur * 100 ) / $totalused         EndIf         ProgressSet( $currPer, Round( $currPer, 0 ) & "%", "Defragmenting " & $var[$i] )         RunWait ( @ComSpec & " /c" & 'DEFRAG ' & $var[$i], "", @SW_HIDE )     Next ProgressSet ( 95, "95%",  'Processing Idle Tasks' )     RunWait ( @WindowsDir & '\System32\rundll32.exe advapi32.dll,ProcessIdleTasks' )     ProgressSet ( 100 , "Done", "Complete" ) EndIf Exit Func gotoExit()         ProgressOff()     Exit EndFunc

Edited by chaos945, 14 August 2004 - 06:54 PM.






#2 Dr.Chi

Dr.Chi

    Seeker

  • Active Members
  • 36 posts

Posted 16 September 2004 - 06:59 PM

I'd like to suggest a slight change in your script.

Func gotoExit()         ProgressOff()     WinActivate("C:\WIN")     SEND ("^C")     Exit EndFunc


Originally your gotoExit function only ended the progress bar and script, but the Defrag utility still ran.

This way it will activate and "CTL C" the defrag process to end it.

(I also changed the @SW_HIDE to @SW_MINIMIZE so I could look at the actual defrag if I needed to).

But Kudos on the good script!

#3 ezzetabi

ezzetabi

    さくらが さいた

  • Active Members
  • PipPipPipPipPipPip
  • 2,011 posts

Posted 17 September 2004 - 07:03 AM

Does it work in Win2000?

#4 Dr.Chi

Dr.Chi

    Seeker

  • Active Members
  • 36 posts

Posted 17 September 2004 - 12:08 PM

Does it work in Win2000?

<{POST_SNAPBACK}>

Nope, unfortunately not. 2000 doesn't support commandline defragging.
As dumb as that may be.

There is a free commandline defragger available for 2000, but I forget where it is I had seen it.

#5 ezzetabi

ezzetabi

    さくらが さいた

  • Active Members
  • PipPipPipPipPipPip
  • 2,011 posts

Posted 17 September 2004 - 04:36 PM

This was the point Dr.Chi... with XP is soo easy make a script since a command line program is avaiable... :ph34r:

#6 chaos945

chaos945

    Seeker

  • Active Members
  • 34 posts

Posted 18 September 2004 - 02:42 AM

This was the point Dr.Chi... with XP is soo easy make a script since a command line program is avaiable... :ph34r:

<{POST_SNAPBACK}>

Doubt this will work but its worth a try, here is defrag.exe directly from winxp Pro, try it on win2k.

Copy to System32

Attached Files


Edited by chaos945, 18 September 2004 - 02:43 AM.


#7 MHz

MHz

    Just simple

  • MVPs
  • 5,400 posts

Posted 19 September 2004 - 02:06 AM

DIRMS is a commandline defrag for Windows 2000. Have not tried it, but it looks like best option. You could alter the script to suit or create your own?

:ph34r:




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users