Jump to content

exit while in loop


am632
 Share

Recommended Posts

Hi,

a while back I asked for some help finishing a check disk utility I was working on and thanks to the people who helped me and a bit of trial and error I have managed to get the check disk utility working exactly as I wanted but there is just 1 problem which remains, I have tried for the past couple of days to fix this by myself but I just have no idea what to do, basically the program wont close either by clicking the cross or pressing esc whilst the loop is in progress - I need the loop because this updates the edit box and the only way I have managed to get the exit to work is to remove the loop, so i'm in a catch 22 situation. Here is the script I currently have...

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

;Variables
Dim $drivearray[100]

;Main GUI
$Main = GUICreate("Check-Disk Utility", 510, 520, -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, 235,$WS_VSCROLL) ;$ES_AUTOVSCROLL
;$EDIT_BOX = GUICtrlCreateEdit("", 16, 272, 481, 193,BitOr($WS_VSCROLL, $ES_AUTOVSCROLL))
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_Command()
EndFunc

Func _Exit_Command()
    If ProcessExists("cmd.exe") Then
    ProcessClose("cmd.exe")
EndIf
    If ProcessExists("chkdsk.exe") Then
    ProcessClose("chkdsk.exe")
EndIf
FileDelete("checkdisklog.txt")
FileDelete("chkdsk_command.bat")
Exit
EndFunc

Func _Start_Function()
$fulllocation = GUICtrlRead($COMBO)
$location = StringLeft($fulllocation, 2)
$TARGET = $location
;envset ("Target", $location)
IF GUICtrlRead($Radio1) = "1" then
;$PID = Run(@ComSpec & " /c" & '@color 17 && @echo. && %systemroot%\system32\chkdsk.exe %Target% >checkdisklog.txt & echo. && pause',"", @SW_HIDE)
FileWrite("chkdsk_command.bat", "chkdsk " & $TARGET & " " & ">checkdisklog.txt")
$PID = Run("chkdsk_command.bat","", @SW_HIDE)
Do
$line = FileRead("checkdisklog.txt")
GUICtrlSetData($EDIT_BOX, $line)
_GUICtrlEdit_Scroll($EDIT_BOX, $SB_SCROLLCARET)
Sleep(2000)
Until ProcessExists("chkdsk.exe") = @error
Sleep(4000)
ProcessClose($PID)
GUICtrlSetData($EDIT_BOX, $line)
_GUICtrlEdit_Scroll($EDIT_BOX, $SB_SCROLLCARET)
FileDelete("chkdsk_command.bat")
MsgBox(0,"","Scan Complete")

ElseIF GUICtrlRead($Radio2) = "1" then
FileWrite("chkdsk_command.bat", "echo y|chkdsk " & $TARGET & " /f " & ">checkdisklog.txt")
$PID = Run("chkdsk_command.bat","", @SW_HIDE)
Do
$line = FileRead("checkdisklog.txt")
GUICtrlSetData($EDIT_BOX, $line)
_GUICtrlEdit_Scroll($EDIT_BOX, $SB_SCROLLCARET)
Sleep(2000)
Until ProcessExists("chkdsk.exe") = @error
Sleep(4000)
ProcessClose($PID)
GUICtrlSetData($EDIT_BOX, $line)
_GUICtrlEdit_Scroll($EDIT_BOX, $SB_SCROLLCARET)
FileDelete("chkdsk_command.bat")
If @HomeDrive = $TARGET Then
$ans = MsgBox(4,"","Scan will start on next boot, would you like to restart your computer now?")
Select
    Case $ans = 6
        Shutdown(6)
    Case $ans = 7
        Sleep(0)
EndSelect
Else
MsgBox(0,"","Scan Complete")
EndIf

ElseIF GUICtrlRead($Radio3) = "1" then
FileWrite("chkdsk_command.bat", "echo y|chkdsk " & $TARGET & " /r " & ">checkdisklog.txt")
$PID = Run("chkdsk_command.bat","", @SW_HIDE)
Do
$line = FileRead("checkdisklog.txt")
GUICtrlSetData($EDIT_BOX, $line)
_GUICtrlEdit_Scroll($EDIT_BOX, $SB_SCROLLCARET)
Sleep(2000)
Until ProcessExists("chkdsk.exe") = @error
Sleep(4000)
ProcessClose($PID)
GUICtrlSetData($EDIT_BOX, $line)
_GUICtrlEdit_Scroll($EDIT_BOX, $SB_SCROLLCARET)
FileDelete("chkdsk_command.bat")
If @HomeDrive = $TARGET Then
$ans = MsgBox(4,"","Scan will start on next boot, would you like to restart your computer now?")
Select
    Case $ans = 6
        Shutdown(6)
    Case $ans = 7
        Sleep(0)
EndSelect
Else
MsgBox(0,"","Scan Complete")
EndIf

EndIF
EndFunc

Please can anyone help me fix my problem?

Thanks

Note: I mentioned this in my other post but I just want to say that not all the code is mine, the select drive box was taken from another chkdsk script and credit is due to them + credit to the people who have helped me with the other code.

Link to comment
Share on other sites

Hi, thanks for the link, to be honest I really dont understand how to intergrate this into my script, if anyone has any spare time would you possibly mind modifying my script to make this work and possibly comment the modifications so I can understand how it works. I realise people are busy and it's not good to just ask someone to do it for you but i'm really stuck on this 1.

Thanks

Link to comment
Share on other sites

  • Moderators

am632,

As the author of the tutorial I am a little disappointed that you were not able to follow it. :)

Here is your script with a few added lines to show you how to integrate some of the code from the tutorial into your script. Look at what I have done and read the comments - then see if you understand why the code works and how to integrate it into your full script. I have left you to do some of the work - best way to learn. :)

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <Process.au3>
#include <ScrollBarConstants.au3>
#include <GuiEdit.au3>

Opt("GUIOnEventMode", 1)
Opt("GUICloseOnESC", 1)

;Variables
Global $drivearray[100], $fInterrupt = 0 ; Create flag to indicate if we should interrupt a running function <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

;Main GUI
$Main = GUICreate("Check-Disk Utility", 510, 520, -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)

;Stop Button
$BUTTON_STOP = GUICtrlCreateButton("Stop", 39, 204, 75, 25, $WS_GROUP) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

;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, 235, $WS_VSCROLL) ;$ES_AUTOVSCROLL
;$EDIT_BOX = GUICtrlCreateEdit("", 16, 272, 481, 193,BitOr($WS_VSCROLL, $ES_AUTOVSCROLL))
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)

; Register the WM_COMMAND message whic is sent by a button press
GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

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

;Functions

Func _CloseApplication()
    If @GUI_CtrlId = $GUI_EVENT_CLOSE Then _Exit_Command()
EndFunc   ;==>_CloseApplication

Func _Exit_Command()
    If ProcessExists("cmd.exe") Then
        ProcessClose("cmd.exe")
    EndIf
    If ProcessExists("chkdsk.exe") Then
        ProcessClose("chkdsk.exe")
    EndIf
    FileDelete("checkdisklog.txt")
    FileDelete("chkdsk_command.bat")
    Exit
EndFunc   ;==>_Exit_Command

Func _Start_Function()
    $fulllocation = GUICtrlRead($COMBO)
    $location = StringLeft($fulllocation, 2)
    $TARGET = $location
    ;envset ("Target", $location)
    If GUICtrlRead($Radio1) = "1" Then

 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        $iBegin = TimerInit()                                       ; This is to simulate the ChkDsk running
        Do                                                          ; This is the Do...Until loop you  already heve
            If $fInterrupt Then                                     ; Look for the interrupt flag
                ConsoleWrite("Interrupting..." & @CRLF)             ; Announce it
                $fInterrupt = 0                                     ; Clear the flag
                ExitLoop                                            ; Exit the loop
            EndIf
            ConsoleWrite("In Loop 1 at " & @SEC & @CRLF)            ; Announce that ChekDsk is still being simulated
            Sleep(1000)                                             ; Save the CPU
        Until TimerDiff($iBegin) > 20000                            ; After 20 secs assume ChekDsk is finished
 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 #cs
        ;$PID = Run(@ComSpec & " /c" & '@color 17 && @echo. && %systemroot%\system32\chkdsk.exe %Target% >checkdisklog.txt & echo. && pause',"", @SW_HIDE)
        FileWrite("chkdsk_command.bat", "chkdsk " & $TARGET & " " & ">checkdisklog.txt")
        $PID = Run("chkdsk_command.bat", "", @SW_HIDE)
        Do
            $line = FileRead("checkdisklog.txt")
            GUICtrlSetData($EDIT_BOX, $line)
            _GUICtrlEdit_Scroll($EDIT_BOX, $SB_SCROLLCARET)
            Sleep(2000)
        Until ProcessExists("chkdsk.exe") = @error
        Sleep(4000)
        ProcessClose($PID)
        GUICtrlSetData($EDIT_BOX, $line)
        _GUICtrlEdit_Scroll($EDIT_BOX, $SB_SCROLLCARET)
        FileDelete("chkdsk_command.bat")
        MsgBox(0, "", "Scan Complete")
#ce
    ElseIf GUICtrlRead($Radio2) = "1" Then

        $iBegin = TimerInit()
        Do
            If $fInterrupt Then
                ConsoleWrite("Interrupting..." & @CRLF)
                $fInterrupt = 0
                ExitLoop
            EndIf
            ConsoleWrite("In Loop 2 at " & @SEC & @CRLF)
            Sleep(1000)
        Until TimerDiff($iBegin) > 20000

#cs
        FileWrite("chkdsk_command.bat", "echo y|chkdsk " & $TARGET & " /f " & ">checkdisklog.txt")
        $PID = Run("chkdsk_command.bat", "", @SW_HIDE)
        Do
            $line = FileRead("checkdisklog.txt")
            GUICtrlSetData($EDIT_BOX, $line)
            _GUICtrlEdit_Scroll($EDIT_BOX, $SB_SCROLLCARET)
            Sleep(2000)
        Until ProcessExists("chkdsk.exe") = @error
        Sleep(4000)
        ProcessClose($PID)
        GUICtrlSetData($EDIT_BOX, $line)
        _GUICtrlEdit_Scroll($EDIT_BOX, $SB_SCROLLCARET)
        FileDelete("chkdsk_command.bat")
        If @HomeDrive = $TARGET Then
            $ans = MsgBox(4, "", "Scan will start on next boot, would you like to restart your computer now?")
            Select
                Case $ans = 6
                    Shutdown(6)
                Case $ans = 7
                    Sleep(0)
            EndSelect
        Else
            MsgBox(0, "", "Scan Complete")
        EndIf
#ce

    ElseIf GUICtrlRead($Radio3) = "1" Then

        $iBegin = TimerInit()
        Do
            If $fInterrupt Then
                ConsoleWrite("Interrupting..." & @CRLF)
                $fInterrupt = 0
                ExitLoop
            EndIf
            ConsoleWrite("In Loop 3 at " & @SEC & @CRLF)
            Sleep(1000)
        Until TimerDiff($iBegin) > 20000

#cs
        FileWrite("chkdsk_command.bat", "echo y|chkdsk " & $TARGET & " /r " & ">checkdisklog.txt")
        $PID = Run("chkdsk_command.bat", "", @SW_HIDE)
        Do
            $line = FileRead("checkdisklog.txt")
            GUICtrlSetData($EDIT_BOX, $line)
            _GUICtrlEdit_Scroll($EDIT_BOX, $SB_SCROLLCARET)
            Sleep(2000)
        Until ProcessExists("chkdsk.exe") = @error
        Sleep(4000)
        ProcessClose($PID)
        GUICtrlSetData($EDIT_BOX, $line)
        _GUICtrlEdit_Scroll($EDIT_BOX, $SB_SCROLLCARET)
        FileDelete("chkdsk_command.bat")
        If @HomeDrive = $TARGET Then
            $ans = MsgBox(4, "", "Scan will start on next boot, would you like to restart your computer now?")
            Select
                Case $ans = 6
                    Shutdown(6)
                Case $ans = 7
                    Sleep(0)
            EndSelect
        Else
            MsgBox(0, "", "Scan Complete")
        EndIf
#ce
    EndIf
EndFunc   ;==>_Start_Function

 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; This is the function we run when we intercept a button press
Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    ; The STOP button was pressed so set the flag
    If BitAND($wParam, 0x0000FFFF) = $BUTTON_STOP Then $fInterrupt = 1
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_COMMAND
 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Come back if you have problems or questions. :)

M23

Edit: Added the script! :mellow:

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

am632 apparently not going to ask what I'm thinking. ... ' :mellow: what script?'

---

Aha. I see it now. :)

Edited by iEvKI3gv9Wrkd41u

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

  • Moderators

iEvKI3gv9Wrkd41u,

what script?

That script! :mellow:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hi, thanks for your help, I have finished the script but I used another example which I found here http://www.zerozaku.com/viewtopic.php?f=57&t=133

Here is the working script for anyone who wants to see

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

;Variables
Dim $drivearray[100], $Var = False, $TempDir = @TempDir & "\"

If FileExists($TempDir & "checkdisklog.txt") Then
    FileDelete($TempDir & "checkdisklog.txt")
EndIf

;Main GUI
$Main = GUICreate("Check-Disk Utility", 510, 520, -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, "_Begin_Start_Function")

;EditBox
$EDIT_BOX = GUICtrlCreateEdit("", 16, 272, 481, 235,$WS_VSCROLL) ;$ES_AUTOVSCROLL
;$EDIT_BOX = GUICtrlCreateEdit("", 16, 272, 481, 193,BitOr($WS_VSCROLL, $ES_AUTOVSCROLL))
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(0)
If $Var Then
        _Start_Function()
    EndIf
WEnd
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;Functions

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

Func _Exit_Command()
    If ProcessExists("cmd.exe") Then
    ProcessClose("cmd.exe")
EndIf
    If ProcessExists("chkdsk.exe") Then
    ProcessClose("chkdsk.exe")
EndIf
Sleep(500)
If FileExists($TempDir & "chkdsk_command.bat") Then
FileDelete($TempDir & "chkdsk_command.bat")
EndIf
If FileExists($TempDir & "checkdisklog.txt") Then
FileDelete($TempDir & "checkdisklog.txt")
EndIf
Exit
EndFunc

Func _Begin_Start_Function()
$Var = True
EndFunc

Func _Start_Function()
$Var = False
GUICtrlSetState($BUTTON_START,$GUI_DISABLE)
$fulllocation = GUICtrlRead($COMBO)
$location = StringLeft($fulllocation, 2)
$TARGET = $location
;envset ("Target", $location)
IF GUICtrlRead($Radio1) = "1" then
;$PID = Run(@ComSpec & " /c" & '@color 17 && @echo. && %systemroot%\system32\chkdsk.exe %Target% >checkdisklog.txt & echo. && pause',"", @SW_HIDE)
FileWrite($TempDir & "chkdsk_command.bat", "chkdsk " & $TARGET & " " & ">" & $TempDir & "checkdisklog.txt")
$PID = Run($TempDir & "chkdsk_command.bat","", @SW_HIDE)
Do
Sleep(2000)
$line = FileRead($TempDir & "checkdisklog.txt")
GUICtrlSetData($EDIT_BOX, $line)
_GUICtrlEdit_Scroll($EDIT_BOX, $SB_SCROLLCARET)
Until ProcessExists("chkdsk.exe") = @error
;Sleep(1000)
ProcessClose($PID)
;GUICtrlSetData($EDIT_BOX, $line)
;_GUICtrlEdit_Scroll($EDIT_BOX, $SB_SCROLLCARET)
FileDelete($TempDir & "chkdsk_command.bat")
MsgBox(0,"","Scan Complete")
GUICtrlSetState($BUTTON_START,$GUI_ENABLE)

ElseIF GUICtrlRead($Radio2) = "1" then
FileWrite($TempDir & "chkdsk_command.bat", "echo y|chkdsk " & $TARGET & " /f " & ">" & $TempDir & "checkdisklog.txt")
$PID = Run($TempDir & "chkdsk_command.bat","", @SW_HIDE)
Do
Sleep(2000)
$line = FileRead($TempDir & "checkdisklog.txt")
GUICtrlSetData($EDIT_BOX, $line)
_GUICtrlEdit_Scroll($EDIT_BOX, $SB_SCROLLCARET)
Until ProcessExists("chkdsk.exe") = @error
;Sleep(1000)
ProcessClose($PID)
;GUICtrlSetData($EDIT_BOX, $line)
;_GUICtrlEdit_Scroll($EDIT_BOX, $SB_SCROLLCARET)
FileDelete($TempDir & "chkdsk_command.bat")
If @HomeDrive = $TARGET Then
$ans = MsgBox(4,"","Scan will start on next boot, would you like to restart your computer now?")
Select
    Case $ans = 6
        Shutdown(6)
    Case $ans = 7
        Sleep(0)
EndSelect
Else
MsgBox(0,"","Scan Complete")
EndIf
GUICtrlSetState($BUTTON_START,$GUI_ENABLE)

ElseIF GUICtrlRead($Radio3) = "1" then
FileWrite($TempDir & "chkdsk_command.bat", "echo y|chkdsk " & $TARGET & " /r " & ">" & $TempDir & "checkdisklog.txt")
$PID = Run($TempDir & "chkdsk_command.bat","", @SW_HIDE)
Do
Sleep(2000)
$line = FileRead($TempDir & "checkdisklog.txt")
GUICtrlSetData($EDIT_BOX, $line)
_GUICtrlEdit_Scroll($EDIT_BOX, $SB_SCROLLCARET)
Until ProcessExists("chkdsk.exe") = @error
;Sleep(1000)
ProcessClose($PID)
;GUICtrlSetData($EDIT_BOX, $line)
;_GUICtrlEdit_Scroll($EDIT_BOX, $SB_SCROLLCARET)
FileDelete($TempDir & "chkdsk_command.bat")
If @HomeDrive = $TARGET Then
$ans = MsgBox(4,"","Scan will start on next boot, would you like to restart your computer now?")
Select
    Case $ans = 6
        Shutdown(6)
    Case $ans = 7
        Sleep(0)
EndSelect
Else
MsgBox(0,"","Scan Complete")
EndIf
GUICtrlSetState($BUTTON_START,$GUI_ENABLE)

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