The script can be stored in on a server, but it will run on whatever workstation runs it.
It would run when the hidden form opens. If it reads that the variable is false, the timer loop would exit and finish running the script, closing the database. When the hidden form is closed, you can end...