Sign in to follow this  
Followers 0
chaos945

Defrag Tool

7 posts in this topic

#1 ·  Posted (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.

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

Share this post


Link to post
Share on other sites



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!

Share this post


Link to post
Share on other sites

Does it work in Win2000?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

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

defrag.zip

Edited by chaos945

Share this post


Link to post
Share on other sites

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:

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0