Juvigy Posted June 8, 2015 Posted June 8, 2015 Any way i can detect if my exe is 'end tasked' ? I would like to display a msgbox or write a log file just before the task is closed.
javiwhite Posted June 8, 2015 Posted June 8, 2015 OnAutoITExitRegister sets @ExitCode & @ExitMethod. I would suggest playing around with that, And seeing how you get on.CheersJavi 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.
Juvigy Posted June 8, 2015 Author Posted June 8, 2015 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 ;==>MyTestFunc2If i kill it with task manager i dont get any msgbox !
Jewtus Posted June 8, 2015 Posted June 8, 2015 If you close something with task manager, it halts the process and wouldn't register an exit message if I'm not mistaken.
Juvigy Posted June 8, 2015 Author Posted June 8, 2015 If you close something with task manager, it halts the process and wouldn't register an exit message if I'm not mistaken.Yes , indeed . So how to do it then?
javiwhite Posted June 8, 2015 Posted June 8, 2015 (edited) 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) EndFuncTaskMonitor.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. CheersJavi EDIT: added file names for example. Edited June 8, 2015 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.
Jewtus Posted June 8, 2015 Posted June 8, 2015 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).
Juvigy Posted June 9, 2015 Author Posted June 9, 2015 I think i remember that it was done some time ago , but cant find the thread. It was using some kind of interception of windows messages.
Jewtus Posted June 9, 2015 Posted June 9, 2015 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.
UEZ Posted June 9, 2015 Posted June 9, 2015 @Jewtus: the functions from the link are now integrated to the _WinAPI_* lib. E.g. _WinAPI_GetParentProcess. Jewtus 1 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Juvigy Posted June 9, 2015 Author Posted June 9, 2015 @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.
zreo15 Posted June 9, 2015 Posted June 9, 2015 (edited) @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 June 9, 2015 by zreo15
Jewtus Posted June 9, 2015 Posted June 9, 2015 (edited) 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 June 9, 2015 by Melba23 Suggestion removed
Moderators Melba23 Posted June 9, 2015 Moderators Posted June 9, 2015 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 Jewtus 1 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Recommended Posts