Jump to content

How to terminate a Script.exe?


Recommended Posts

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.

Link to comment
Share on other sites

  • Moderators

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.

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

Link to comment
Share on other sites

  • Moderators

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.

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

Link to comment
Share on other sites

  • Moderators

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.

Link to comment
Share on other sites

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

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

Link to comment
Share on other sites

  • 2 weeks later...

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

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

Link to comment
Share on other sites

  • Moderators

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

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

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