Jump to content
Sign in to follow this  
SoulBlade

CHKDSK GUI using 100% CPU

Recommended Posts

SoulBlade

Hi!

With the help on this forum i've created a CHKDSK GUI.

Altought it works, it uses 100% of CPU when it's running.

CODE
AutoItSetOption("TrayIconHide", 1)

#include <GUIConstants.au3>

#include <Array.au3>

Opt("GUIOnEventMode", 1)

Dim $drivearray[100]

GuiCreate("CHKDSK", 330, 235)

GUISetIcon("CHKDSK.ICO", 0)

GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")

GUICtrlCreateGroup ("Check Disk ", 10, 10, 310, 90)

$ReadOnly = GUICtrlCreateRadio ("Read-only mode", 40, 30, 100, 20)

$Fix = GUICtrlCreateRadio ("Fix errors on the disk", 40, 50, 120, 20)

$Recover = GUICtrlCreateRadio ("Locate bad sectors and recovers information", 40, 70, 265, 20)

GUICtrlSetState ($Recover,$GUI_CHECKED)

GUICtrlCreateGroup ("",-99,-99,1,1)

GUICtrlCreateGroup ("",10,170,310,50)

$nan=GUICtrlCreateLabel("© Soul]B[lade", 260, 221, 60, 12)

GUICtrlSetFont($nan,7)

;--------------- Build-up list of disks that can be checked ---------------

$drives = DriveGetDrive("ALL")

$drivelist = ""

$y = 1

For $i = 1 to $drives[0]

$DriveType = DriveGetType($drives[$i])

If $DriveType = "Removable" or $DriveType = "Fixed" or $DriveType = "RAMDisk" then

$drivearray[$y] = $drives[$i]

$y = $y + 1

EndIf

Next

$drivearray[0] = $y - 1

_ArraySort($drivearray, 0, 0, $y - 1)

If NOT @error Then

For $i = 1 to $drivearray[0]

$drivearray[$i] = StringUpper($drivearray[$i])

$DriveStatus = DriveStatus($drivearray[$i])

if $DriveStatus = "NOTREADY" then

$DriveInfo = "drive is empty"

elseif $DriveStatus = "UNKNOWN" then

$DriveInfo = "may be unformatted"

else

$DriveInfo = DriveGetLabel($drivearray[$i])

if $DriveInfo = "" then $DriveInfo = "has no label"

endif

$drivearray[$i] = String($drivearray[$i] & " [" & $DriveInfo & "]")

If $i > 1 Then

$drivelist = $drivelist & "|"

Endif

$drivelist = $drivelist & $drivearray[$i]

Next

EndIf

If $drivelist = "" Then

; no suitable drives found, show all drive letters

$drivelist = "A:|B:|C:|D:|E:|F:|G:|H:|I:|J:|K:|L:|M:|N:|O:|P:|Q:|R:|S:|T:|U:|V:|W:|X:|Y:|Z:"

$defaultdrive = "C:"

Else

$defaultdrive = $drivearray[1]

Endif

GUICtrlCreateGroup ("Select Disk ", 10, 110, 310, 50)

$Drive = GUICtrlCreateCombo ("", 50,130,230)

GUICtrlSetData(-1, $drivelist, $defaultdrive)

$OKID = GuiCtrlCreateButton("RUN", 130, 186, 75, 23)

GUICtrlSetOnEvent($OKID,"OnOK")

GUISetState ()

While 1

Wend

;--------------- Functions ---------------

Func OnOK()

$fulllocation = GUICtrlRead($Drive)

$location = StringLeft($fulllocation, 2)

envset ("Target", $location)

IF GUICtrlRead($ReadOnly) = "1" then

WinSetState ( "Microsoft Check Disk", "", @SW_MINIMIZE)

Run(@ComSpec & " /c" & '@color 17 && @echo. && %systemroot%\system32\chkdsk.exe %Target% & echo. && pause',"")

exit

ElseIF GUICtrlRead($Fix) = "1" then

WinSetState ( "Microsoft Check Disk", "", @SW_MINIMIZE)

Run(@ComSpec & " /c" & '@color 17 && @echo. && %systemroot%\system32\chkdsk.exe %Target% /F & echo. && pause',"")

exit

ElseIF GUICtrlRead($Recover) = "1" then

WinSetState ( "Microsoft Check Disk", "", @SW_MINIMIZE)

Run(@ComSpec & " /c" & '@color 17 && @echo. && %systemroot%\system32\chkdsk.exe %Target% /R & echo. && pause',"")

exit

EndIF

WinSetState ( "Microsoft Check Disk", "", @SW_RESTORE)

EndFunc

Func OnCANCEL()

Exit

EndFunc

Func SpecialEvents()

If @GUI_CTRLID = $GUI_EVENT_CLOSE Then Exit

EndFunc

Please help me find the problem.

:)

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.