Jump to content
Sign in to follow this  
dreamzboy

Closing the script while it's running

Recommended Posts

dreamzboy

So I ran the script, I tried clicking on the X button in the window to close the script to stop all actions and it doesn't work. Any ideas? My guess is that the script is running too fast for my click.

Thanks in advance.

-Dreamzboy-

#include <GuiConstants.au3>

Opt("TrayIconDebug", 1)

GUICreate ("Test", 315, 174, -1, -1)

Global $CheckBoxes[8] = ["NAI 8.5", "Windows Defender", "Adobe Acrobat 8.0", "WinZip", "VNC", "Nortel Contivity", "SecureCRT", "Exceed 7.0"]
$CheckBoxes[0] = GUICtrlCreateCheckbox($CheckBoxes[0], 35, 44, 60, 20)
$CheckBoxes[1] = GUICtrlCreateCheckbox($CheckBoxes[1], 35, 74, 110, 20)
$CheckBoxes[2] = GUICtrlCreateCheckbox($CheckBoxes[2], 35, 104, 110, 20)
$CheckBoxes[3] = GUICtrlCreateCheckbox($CheckBoxes[3], 35, 134, 60, 20)
$CheckBoxes[4] = GUICtrlCreateCheckbox($CheckBoxes[4], 185, 44, 50, 20)
$CheckBoxes[5] = GUICtrlCreateCheckbox($CheckBoxes[5], 185, 74, 90, 20)
$CheckBoxes[6] = GUICtrlCreateCheckbox($CheckBoxes[6], 185, 104, 80, 20)
$CheckBoxes[7] = GUICtrlCreateCheckbox($CheckBoxes[7], 185, 134, 80, 20)

GUISetState (@SW_SHOW)

$Heading = "Service is Stopping"
GUICtrlCreateLabel($Heading, 0, 14, 315, 20, $SS_CENTER)

Sleep (1000)

For $i = 0 To 7 Step 1
    $msg = GUIGetMsg ()
    If $msg = $GUI_EVENT_CLOSE Then Exit        
    GUICtrlSetState ($CheckBoxes[$i], $GUI_INDETERMINATE)
    GUICtrlSetState ($CheckBoxes[$i], $GUI_DISABLE)
    Sleep (1000)
Next
    MsgBox (0, "", "Services has stopped successfully", 2)
    
For $i = 0 To 7 Step 1
    GUICtrlSetState ($CheckBoxes[$i], $GUI_UNCHECKED)
    GUICtrlSetState ($CheckBoxes[$i], $GUI_ENABLE)
Next

$Heading = "Service is Starting"
GUICtrlCreateLabel($Heading, 0, 14, 315, 20, $SS_CENTER)
For $i = 0 To 7 Step 1
    GUICtrlSetState ($CheckBoxes[$i], $GUI_INDETERMINATE)
    GUICtrlSetState ($CheckBoxes[$i], $GUI_DISABLE)
    Sleep (1000)
Next
    MsgBox (0, "", "Services has started successfully", 2)

Share this post


Link to post
Share on other sites
Nahuel

Try it onevent mode:

#include <GuiConstants.au3>

Opt("TrayIconDebug", 1)
Opt("GUIOnEventMode", 1)

GUICreate ("Test", 315, 174, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE,"_exit")

Global $CheckBoxes[8] = ["NAI 8.5", "Windows Defender", "Adobe Acrobat 8.0", "WinZip", "VNC", "Nortel Contivity", "SecureCRT", "Exceed 7.0"]
$CheckBoxes[0] = GUICtrlCreateCheckbox($CheckBoxes[0], 35, 44, 60, 20)
$CheckBoxes[1] = GUICtrlCreateCheckbox($CheckBoxes[1], 35, 74, 110, 20)
$CheckBoxes[2] = GUICtrlCreateCheckbox($CheckBoxes[2], 35, 104, 110, 20)
$CheckBoxes[3] = GUICtrlCreateCheckbox($CheckBoxes[3], 35, 134, 60, 20)
$CheckBoxes[4] = GUICtrlCreateCheckbox($CheckBoxes[4], 185, 44, 50, 20)
$CheckBoxes[5] = GUICtrlCreateCheckbox($CheckBoxes[5], 185, 74, 90, 20)
$CheckBoxes[6] = GUICtrlCreateCheckbox($CheckBoxes[6], 185, 104, 80, 20)
$CheckBoxes[7] = GUICtrlCreateCheckbox($CheckBoxes[7], 185, 134, 80, 20)

GUISetState (@SW_SHOW)


$Heading = "Service is Stopping"
GUICtrlCreateLabel($Heading, 0, 14, 315, 20, $SS_CENTER)

Sleep (1000)

For $i = 0 To 7 Step 1      
    GUICtrlSetState ($CheckBoxes[$i], $GUI_INDETERMINATE)
    GUICtrlSetState ($CheckBoxes[$i], $GUI_DISABLE)
    Sleep (1000)
Next
    MsgBox (0, "", "Services has stopped successfully", 2)
    
For $i = 0 To 7 Step 1
    GUICtrlSetState ($CheckBoxes[$i], $GUI_UNCHECKED)
    GUICtrlSetState ($CheckBoxes[$i], $GUI_ENABLE)
Next

$Heading = "Service is Starting"
GUICtrlCreateLabel($Heading, 0, 14, 315, 20, $SS_CENTER)
For $i = 0 To 7 Step 1
    GUICtrlSetState ($CheckBoxes[$i], $GUI_INDETERMINATE)
    GUICtrlSetState ($CheckBoxes[$i], $GUI_DISABLE)
    Sleep (1000)
Next
    MsgBox (0, "", "Services has started successfully", 2)

Func _exit()
    Exit
EndFunc

Share this post


Link to post
Share on other sites
dreamzboy

Wow you're good. In 17 minutes..not bad. Thanks for the help. I really do appreciated. I was reading up on GuiSetOnEvent, but wasn't sure how to use it, but now I do.

Cheers!

<_<

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.