Jump to content

Need help finishing this check disk utility please


am632
 Share

Recommended Posts

Hi,

I'll just start by saying at least half the code used in this tool is NOT mine - I beleive it is by SoleBlade and is posted here I am just putting this together to learn how it works and to make modifications.

So what I'm trying to do now is get the cmd output to appear in the EDIT_BOX activly as it is running. I Have searched around and read the help-file and think I need to use stdoutRead() somewhere but I dont know how to implement it. Could anyone possibly help please?

Here is the code

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
Opt("GUIOnEventMode", 1)
Opt("GUICloseOnESC", 1)

;Variables
Dim $drivearray[100]

;Main GUI
$Main = GUICreate("Check-Disk Utility", 510, 478, -1, -1)
GUISetBkColor(0xFFFFFF)
$Pic1 = GUICtrlCreatePic("Images\HDD.bmp", 12, 32, 128, 100, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
GUISetState(@SW_SHOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseApplication")

;Group 1 [Description Labels]
$Group1 = GUICtrlCreateGroup("", 152, 8, 345, 89)
$DESCRIPTION1 = GUICtrlCreateLabel("This is a simple tool which checks a volume for", 163, 19, 328, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$DESCRIPTION2 = GUICtrlCreateLabel("Problems and attemps to fix them if any are ", 163, 44, 312, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$DESCRIPTION3 = GUICtrlCreateLabel("Found.", 163, 71, 54, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)

;Group 2 [Radio Buttons]
$Group2 = GUICtrlCreateGroup("", 152, 104, 345, 97)
$Radio1 = GUICtrlCreateRadio("Read-Only", 176, 121, 137, 17)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Radio2 = GUICtrlCreateRadio("Repair Errors", 176, 145, 145, 17)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Radio3 = GUICtrlCreateRadio("Locate Bad-Sectors & Repair", 176, 169, 241, 17)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetState ($Radio2,$GUI_CHECKED)
GUICtrlCreateGroup("", -99, -99, 1, 1)

;Start Button
$BUTTON_START = GUICtrlCreateButton("Start", 39, 234, 75, 25, $WS_GROUP)
GUICtrlSetOnEvent($BUTTON_START, "_Start_Function")
GUISetState ()

;EditBox
$EDIT_BOX = GUICtrlCreateEdit("", 16, 272, 481, 193)
GUICtrlSetData($EDIT_BOX, "Click the Start Button to Begin...")
GUICtrlSetFont($EDIT_BOX, 10, 400, 0, "MS Sans Serif")

;--------------- Build-up list of disks that can be checked --------------- NOT MY CODE, TAKEN FROM ANOTHER CHECK DISK UTILITY.

$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

;Combo Box
$Label1 = GUICtrlCreateLabel("Select Drive to Scan", 164, 209, 148, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$COMBO = GUICtrlCreateCombo("", 168, 236, 313, 25)
GUICtrlSetData(-1, $drivelist, $defaultdrive)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
While 1
Sleep(250)
WEnd
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;Functions

Func _CloseApplication()
If @GUI_CTRLID = $GUI_EVENT_CLOSE Then Exit
EndFunc

Func _Start_Function()
$fulllocation = GUICtrlRead($COMBO)
$location = StringLeft($fulllocation, 2)
envset ("Target", $location)
IF GUICtrlRead($Radio1) = "1" then
$PID = Run(@ComSpec & " /c" & '@color 17 && @echo. && %systemroot%\system32\chkdsk.exe %Target% & echo. && pause',"", @SW_HIDE)

ElseIF GUICtrlRead($Radio2) = "1" then
$PID = Run(@ComSpec & " /c" & '@color 17 && @echo. && %systemroot%\system32\chkdsk.exe %Target% /F & echo. && pause',"", @SW_HIDE)

ElseIF GUICtrlRead($Radio3) = "1" then
$PID = Run(@ComSpec & " /c" & '@color 17 && @echo. && %systemroot%\system32\chkdsk.exe %Target% /R & echo. && pause',"", @SW_HIDE)

EndIF
EndFunc

Thanks

Link to comment
Share on other sites

This probably isn't the best way, but you could get chkdsk.exe to write an output file and read the last few lines of it and set the data to your gui. The only problem with that is it writes a bunch of "xx Percent Completed" lines. I do not have time right now to play with it more, but try the code below and see if it gives you any ideas. One thing about it is that it runs chkdsk.exe in the background, which is what you were doing.

#include <Process.au3> 
_RunDOS("chkdsk.exe c: >c:\checkdisklog.txt")

#include <ByteMe.au3>

Link to comment
Share on other sites

Hi, thanks for the help.

The only way I have managed to get some visible results are by using the following code...

IF GUICtrlRead($Radio1) = "1" then
$PID = Run(@ComSpec & " /c" & '@color 17 && @echo. && %systemroot%\system32\chkdsk.exe %Target% >checkdisklog.txt & echo. && pause',"", @SW_HIDE)
Do
$line = FileRead("checkdisklog.txt")
GUICtrlSetData($EDIT_BOX,"")
GUICtrlSetData($EDIT_BOX, $line)
Sleep(1000)
Until ProcessExists($PID) Not

Just a few niggles, First even when the chkdsk.exe process has finished a cmd.exe process remains open in task manager, the editbox keeps trying to refresh even when the chkdsk.exe has finished. I a'm unable to close the program using the 'cross' or the esc key whils the chkdsk is running, and the edit box wont auto scroll. I have tried adding $ES_AUTOVSCROLL to the edit box with no luck and I have tried various things regards the refresh thing, i think an exitloop might need to be used in here somewhere but i'm not sure.

Any Ideas?

Thanks

[EDIT] Note that if I get rid of the Do Until, it will allow me to exit the program as I want but the Edit box wont auto update.

Thanks

Edited by am632
Link to comment
Share on other sites

The Until Statement is poorly formatted.

Until NOT ProcessExists($PID)

or

Until ProcessExists($PID) = 0

Personally I would probably have chosen a While/WEnd loop there anyway.

While ProcessExists($PID)
  ;;Put your code in here
WEnd

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Hi, Thanks for the suggestions, The while statement does look better but the script still seems to work exactly the was it has been. Heres the code Im using now...

While ProcessExists($PID)
$line = FileRead("checkdisklog.txt")
GUICtrlSetData($EDIT_BOX,"")
GUICtrlSetData($EDIT_BOX, $line)
Sleep(1000)
WEnd

Do I need an ExitLoop in here somewhere? But also the close button still doesnt currently work once the chkdsk has started and I dont know where to start with that problem.

Thansk for ur help.

Link to comment
Share on other sites

The reason that it does not close while running the checkdisk is because it is not reading the while loop, as it is only single threaded. I am not certain, but I believe that if you use the command "GUISetonevent", and a function which exits the program, you may get somewhere.

Link to comment
Share on other sites

Hi, I'm already using Opt("GUIOnEventMode", 1), GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseApplication"), and the function...

Func _CloseApplication()
If @GUI_CTRLID = $GUI_EVENT_CLOSE Then _Exit_Command()
EndFunc

in my script and it does actually work just not once the start button is pressed which then runs another function that contains a while statement. I figured that the close button doesnt work if there is a while statement in my start function however if I take the while statement out it will fix the close issue but will then not update the edit_box with the command info. Basically if I fix 1 issue I break the other and vice-versa :/

Any Ideas? Thanks for ur suggestion

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...