Sign in to follow this  
Followers 0
qwert

How to terminate a Script.exe?

16 posts in this topic

I have a simple script that defines a HotKey and then waits (sometimes a long time) for the user to either press it -- or press Esc to exit this key monitoring script. The script is compiled and is essentially this:

HotKetSet("[ESC]", "Terminate")

While 1
Sleep(10000)
WEnd

Func Terminate()
    MsgBox(4, "Escape was pressed", "Exiting", 2)
    Exit
EndFunc

When the user presses Esc, the script gives the message and, indeed, exits. It will no longer respond to the Esc key. The problem is that Windows Task Manager continues to show Script.exe running.

How do I get the Script.exe to actually terminate as part of the Esc/Exit?

Thanks for any assistance.

Share this post


Link to post
Share on other sites



click the message box button :P


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

click the message box button :P

OK, that worked .... but where does that leave me?

Do I prompt the user to press that key after they've already pressed Esc?

Or do I try some type of Send ... like starting another script just to send a key back to this one?

And is this due to the Sleep(10000)? If so, is there a better way to "idle" waiting for a hot key?

Thanks for your help.

Share this post


Link to post
Share on other sites

OK, that worked .... but where does that leave me?

Do I prompt the user to press that key after they've already pressed Esc?

Or do I try some type of Send ... like starting another script just to send a key back to this one?

And is this due to the Sleep(10000)? If so, is there a better way to "idle" waiting for a hot key?

Thanks for your help.

The last parameter is a timeout for the MsgBox() function. If you are going to use a message box, and they aren't going to use it, and you want it to dissipate after a period of time, then give it a timeout.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

The last parameter is a timeout for the MsgBox() function. If you are going to use a message box, and they aren't going to use it, and you want it to dissipate after a period of time, then give it a timeout.

Isn't there a 2 second timeout in there already?

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Isn't there a 2 second timeout in there already?

You're absolutely correct, and if it were compiled with SciTe you might even see the issues.
HotKeySet("{ESC}", "Terminate")

While 1
Sleep(10000)
WEnd

Func Terminate()
    MsgBox(4, "Escape was pressed", "Exiting", 2)
    Exit
EndFunc
Compare the two.

Edit:

Just an example of not paying attention to spelling and or how to use functions (you used square brackets when it should have been curly for ESC) and misspelled HotKeySet

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Isn't there a 2 second timeout in there already?

I think I misunderstood that first response. The button I pressed was the one the user would have pressed to make the script perform its main function. It obviously caused the Script.exe to break out of the Sleep(10000) and shutdown completely since the Exit had already take place.

So my questions still stand. How am I supposed to "off" the Script.exe?

P.S. My apology for the slopping script code example in my post. The script was on another machine so I couldn't cut and paste like I usually do -- and it was late. Sorry for the confusion.

Edited by qwert

Share this post


Link to post
Share on other sites

You're absolutely correct, and if it were compiled with SciTe you might even see the issues.

HotKeySet("{ESC}", "Terminate")

While 1
Sleep(10000)
WEnd

Func Terminate()
    MsgBox(4, "Escape was pressed", "Exiting", 2)
    Exit
EndFunc
Compare the two.

Edit:

Just an example of not paying attention to spelling and or how to use functions (you used square brackets when it should have been curly for ESC) and misspelled HotKeySet

Spotted now, cheers

Share this post


Link to post
Share on other sites

Not sure exactly what the purpose is, but I had something similar. Here's how I did it:

Set $flag to 1 then when you hit {ESC} it will call Terminate and do whatever needs to be done, if anything, after the While loop.

HotKeySet("{ESC}", "Terminate")

Dim $flag=1

While $flag
WEnd

;Do whatever
MsgBox("0", "Info", "User hit ESC key")
Exit

Func Terminate()
    $flag=0
EndFunc

I'm still learning.... :P

Good luck!

Share this post


Link to post
Share on other sites

Set $flag to 1 then when you hit {ESC} it will call Terminate and do whatever needs to be done, if anything, after the While loop.

Thanks. I think I see how that will work. I'll try it.

BTW, I've reread the help sections on "GUI Reference - OnEvent Mode" and associated topics. I don't see anything that addresses this phenomena of "lingering script executables". Is it normal? If not, can someone explain what my script is doing to cause it?

Share this post


Link to post
Share on other sites

... phenomena of "lingering script executables". Is it normal? If not, can someone explain what my script is doing to cause it?

For anyone who finds this thread:

Apparently, it IS "normal" for a script to linger on in a sort of zombie state -- it won't respond, but it's still an active windows task -- if you don't disable the hotkeys that you defined before exiting.

For example, if you use the Escape button, disabling it with with HotKeySet("{ESC}") solves the problem. The task disappears from the windows task monitor immediately upon Exit.

If someone has a better solution, I'd like to hear it -- but, otherwise, I'm considering this solved.

Share this post


Link to post
Share on other sites

I can not confirm this behavior. I just ran a script with a wait loop and a hotkey that called exit. The script ended correctly.

Share this post


Link to post
Share on other sites

I can not confirm this behavior. I just ran a script with a wait loop and a hotkey that called exit. The script ended correctly.

Just to clarify: what I'm seeing is that on Windows Task Manager >> Processes the script still shows up as an active task. This is after I've applied the $flag technique mentioned earlier.

I'm running XP SP3 and AutoIt v3.3.0.0

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Yes. I looked at the task manager and my script ended immediately. I only ever have the processes tab open since trying to close "applications" doesn't work when programs are locked up.

Edited by Richard Robertson

Share this post


Link to post
Share on other sites

qwert,

I can confirm Richard Robertson's result on my machine. Pressing ESC while the compiled script was running resulted in the process ending in TaskManager immediately the MsgBox was clicked or timed out.

Autoit 3.3.0.0 and Vista x32.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

I can confirm Richard Robertson's result on my machine.

Thanks to you both. Although the change I made (turning off the hotkeys) solved my immediate problem, based on your results, I'm going to take another look to see if I can't isolate some other problem. My runtime script monitors two different keys and for one of them, tests whether a particular task is running. I've observed the condition I reported on four different PCs, including on running Vista. I'll continue to look and will post any new result.

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  
Followers 0