Jump to content

Recommended Posts

Posted

I'm calling a defrag of my systemdrive at the very end of my WPI list as follows:

call %SystemRoot%\system32\defrag.exe %SystemDrive% -f

Is there a way to get a progress bar on this, by launching from AutoIt or something? Would be nice, cause this process takes a while...


Posted

Defrag.exe is not too verbal for even the AutoIt Beta stdio to get information from.

You could try to automate the Defrag Gui.

Here is some code to get you started.

Run(@SystemDir & '\mmc.exe dfrg.msc', @SystemDir)
If WinWait('Disk Defragmenter', '', 10) Then
ControlFocus('Disk Defragmenter', '', 'SysListView321'); Focus drive selection.
ControlSend('Disk Defragmenter', '', 'SysListView321', '{DOWN}'); Next Drive.
ControlClick('Disk Defragmenter', '', 'Button1'); Analyze.
;~ ControlClick('Disk Defragmenter', '', 'Button2'); Defrag.
EndIf

The above will analyze D: drive.

Posted (edited)

Oh never mind. Hmm yeh that will bring up the GUI. What would be neat though is JUST a progress bar from autoit, nothing else. But maybe its impossible :(

Edited by BoardBabe
  • 3 weeks later...
Posted

Yeah, this one is tough. Tying an action to a process is one thing, but when the process will not reveal itself then you're stuck guessing. I have "settled" on a splash text that hides the command window for the duration of the defrag process:

SplashTextOn("", "" & @CRLF & "Defragmenting the C: partition..."  & @CRLF & "", 275, 58, -1, -1, 1, "Arial", 12, 12)
RunWait ( @ComSpec & " /c defrag c: -f", "", @SW_HIDE )
SplashOff()

Pretty boring to be sure, but I know it is working and I'm not trying to entertain an audience. :P I just want it to look clean.

Here are some script ideas with promise found at MHz's other hangout: HERE. This adaptation seems to work pretty well, and the $TimeLimit variable can be adjusted with quite a bit of accuracy depending upon the fragmentation level at any given point during the install:

Func renew()
$TimeLimit = 10000
$start = TimerInit()
$pid = Run(@ComSpec & " /c defrag c: -f", "", @SW_HIDE )
ProgressOn( "Progress", "Defragmenting the C: partition")
While ProcessExists( $pid )
$current = TimerDiff($start)
ProgressSet( $current * 100 / $TimeLimit)
Sleep(20)
WEnd
ProgressOff()
EndFunc;==>renew

renew()

The required tweaking is well-suited for the perfectionist. If anyone can devise a way to tie a progress bar to the actual length of the defrag process, I will lobby to add another star to their profile. :D

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