Jump to content
Sign in to follow this  

my GUI window exit not working..

Recommended Posts


can somonehelp fix this so it exits the script when the red X is clicked to close the window.

ive created this automatic script for defragmenting which has a skip button to cancel if not required. the button & script works a treat just not the close window button.

Opt("GUIOnEventMode", 1) ; Change to OnEvent mode

$started = 1

$mainwindow = GUICreate("Defragmentation", 200, 100)

GUICtrlCreateLabel("Automating defrag in 6 seconds", 30, 10)

$btnExit = GUICtrlCreateButton("Skip", 70, 50, 60)

;GUISetOnEvent($GUI_EVENT_CLOSE, "_Terminate")

GUICtrlSetOnEvent($btnExit, "_Terminate")


While 1


If $started Then

Run("defrag.exe c: -f", "", @SW_HIDE)




Func _Terminate()

$started = 0



Share this post

Link to post
Share on other sites

You need to add #include <GUIConstants.au3> at the beging of the script. Also remove the semicolon from ;GUISetOnEvent($GUI_EVENT_CLOSE, "_Terminate")

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

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.