You can use the launch before command to run the script. In the launch after you can use taskkill /IM name of your script.ahk to terminate the script. Depending on your OS, the command might be tskill, you can google to find out which, or try one and then the other.