Imbuter2000 Posted February 16, 2019 Share Posted February 16, 2019 I have a script that does safe things most of time. When particular situations are detected, it sends an email and log the action ("email xyz sent - timestamp") into a file. Some times I want to manually Exit the script (for making corrections or just pausing it) by clicking Exit on the tray icon of the script, or by ctrl+break if launched inside SciTE. In this, there is a minimal risk that I exit the script in the middle between the send email and the log actions, although there're immediately consecutive. What's the most proper way to avoid this risk? I'd like something like this: - code... - code... - code... - #disable Exit <- how to do this? - send email - log email sent - #enable Exit <- how to do this? - code... - code... Link to comment Share on other sites More sharing options...
Earthshine Posted February 16, 2019 Share Posted February 16, 2019 You mean you want to block the user from manually exiting? My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
Nine Posted February 16, 2019 Share Posted February 16, 2019 You could use BlockInput but you must have #RequireAdmin with the annoying UAC that comes along. If you want a pseudo-disable, you could define all the "risk" keys (like alt-f4) with HotKeySet () and eat those keys. For the mouse you could use the _MouseTrap () trick like this : $pos = MouseGetPos () _MouseTrap ($pos[0],$pos[1]) “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
pixelsearch Posted February 16, 2019 Share Posted February 16, 2019 (edited) Hi Imbuter2000 Just tried this, it seems to do the job. The following script will hide the tray icon after 5 seconds (and during 5 seconds), then it will reappear. During these 5 "eclipse" seconds, Ctrl-Break won't stop the script. AdlibRegister("MyAdLibFunc", 1000) ; each second Sleep(15000) ; 15s AdlibUnRegister("MyAdLibFunc") MsgBox(0, "", "Finished") Func MyAdLibFunc() Local Static $iCount = 0 $iCount += 1 ConsoleWrite("MyAdLibFunc called " & $iCount & " time" & _ (($iCount > 1) ? ("s") : ("")) & @CRLF) Switch $iCount Case 5 ConsoleWrite("Hiding Tray Icon, Disabling Control+Break during 5 seconds" & @CRLF) Opt("TrayIconHide", 1) ;0=show, 1=hide tray icon HotKeySet("^{BREAK}", "Unbreakable") Case 10 ConsoleWrite("Showing Tray Icon, Enabling Control+Break" & @CRLF) Opt("TrayIconHide", 0) ;0=show, 1=hide tray icon HotKeySet("^{BREAK}") EndSwitch EndFunc ;==>MyAdLibFunc Func Unbreakable() ; MsgBox(0, "", "Ctrl+Break pressed") Return ;==>Unbreakable You could use both instructions Opt("TrayIconHide") and HotKeySet("^{BREAK}") placed in your script, at the moment you don't want your script to be exited, then reuse them a bit later to go back to normal, using appropriate syntax. Edited February 16, 2019 by pixelsearch Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now