chaos945 Posted August 13, 2004 Posted August 13, 2004 (edited) 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. expandcollapse popupHotKeySet( "{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 August 14, 2004 by chaos945
Dr.Chi Posted September 16, 2004 Posted September 16, 2004 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!
Dr.Chi Posted September 17, 2004 Posted September 17, 2004 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.
ezzetabi Posted September 17, 2004 Posted September 17, 2004 This was the point Dr.Chi... with XP is soo easy make a script since a command line program is avaiable...
chaos945 Posted September 18, 2004 Author Posted September 18, 2004 (edited) This was the point Dr.Chi... with XP is soo easy make a script since a command line program is avaiable... <{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 System32defrag.zip Edited September 18, 2004 by chaos945
MHz Posted September 19, 2004 Posted September 19, 2004 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?
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now