Jump to content

How to do an action if Autoit is closed by taskmanager?


Recommended Posts

OnAutoITExitRegister sets @ExitCode & @ExitMethod. I would suggest playing around with that, And seeing how you get on.

Cheers

Javi

give a man an application, and he'll be frustrated for the day, Teach him how to program applications and he'll be frustrated for a lifetime.

Link to comment
Share on other sites

OnAutoItExitRegister("MyTestFunc")
OnAutoItExitRegister("MyTestFunc2")

Sleep(10000)

Func MyTestFunc()
    MsgBox(64, "Exit Results 1", @ExitMethod)
EndFunc   ;==>MyTestFunc

Func MyTestFunc2()
    MsgBox(64, "Exit Results 2", @ExitMethod)
EndFunc   ;==>MyTestFunc2

If i kill it with task manager i dont get any msgbox !

Link to comment
Share on other sites

Ahh i see your problem now.

A quick google of the subject shows that OnAutoITExitRegister func does not handle script crashes or force closures (Such as task manager). I would advise you have a sub process that monitors your script and is called on startup, Then add an OnExit event that creates a flag with the exit method. If the process no longer exists and the monitor picks it up, It can check for the flag, and if the flag does not exist, The script has either crashed, or been forcefully closed.

A working example:

Main.exe:

OnAutoItExitRegister("exitfunc")

ShellExecute(@WorkingDir & "\TaskMonitor.exe",@AutoItPID)
sleep(10000)

func exitFunc()
    FileWriteLine(@WorkingDir & "\ExitMethod.flg",@exitMethod)
EndFunc

TaskMonitor.exe:

if $CMDLINE[0] = 0 then Exit

while 1
    sleep(10)
    if ProcessExists($CMDLINE[1]) then ContinueLoop
    If FileExists(@WorkingDir & "\ExitMethod.flg") then
        MsgBox(0,0,"Exited via normal method")
        FileDelete(@workingDir & "\ExitMethod.flg")
    Else
        Msgbox(0,0,"Force closed or crashed")
    EndIf
    
    Exit
WEnd

 

Obviously that's a rudimentary example, But hopefully it helps get you on the right tracks.

 

Cheers

Javi

 

EDIT: added file names for example.

Edited by javiwhite

give a man an application, and he'll be frustrated for the day, Teach him how to program applications and he'll be frustrated for a lifetime.

Link to comment
Share on other sites

I'd say @javiwhite has the right idea, but doing it from within the script itself I don't think is possible. I have some scripts on my computer that monitor for when my services crash and automatically restart them (if the process doesn't exist, then it sends a force close to the process name just in case its stuck, then delays 10 seconds and restarts the service and waits 2 minutes).

Link to comment
Share on other sites

Something like this?

This would do essentially what you are talking about, but again, its a different application because when you end a thread on task manager, you would need another application to catch the message because the thread has been halted and can no longer perform any functions. Its pretty easy to pack each script as an exe then create a launcher so the launcher can run in the background and capture exit codes and errors. I've even got compile commands set in some of my scripts to compile the subapps so I can deploy everything all at once. If you want an example I'll post it.

Link to comment
Share on other sites

@Jewtus: the functions from the link are now integrated to the _WinAPI_* lib. E.g. _WinAPI_GetParentProcess.

 

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

@Jewtus: I will have a look. Basically what the elegant way was doing was to intercept the 'end task' , and prevent it from executing. Then write a log / display msgbox and shutdown the app.

Link to comment
Share on other sites

@Jewtus: I will have a look. Basically what the elegant way was doing was to intercept the 'end task' , and prevent it from executing. Then write a log / display msgbox and shutdown the app.

​well i guess this is how you create virus if you can manage to interupt it and prevent from executing end task...... curious anyone willing to share how it can be done

Edited by zreo15
Link to comment
Share on other sites

Isn't using autoit for game bots and malware against the rules?

Juvi, out of boredom I did some searching and from what I see about other programming languages and executions on windows, the only things that cannot be end tasked are windows services (native windows services... so creating a service might not work) since windows 98.

<snip>

Edited by Melba23
Suggestion removed
Link to comment
Share on other sites

  • Moderators

Juvigy,

Basically what the elegant way was doing was to intercept the 'end task' , and prevent it from executing.

 Not something we want to discuss here - thread locked.

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

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...