Detect or intercept moment when a batch is closed via mouse (X console button)
===

I need to run a batch "Script A" and this is only run either when the batch is closed programatically via the "Do you want to exit [y / n] questions" or when all the scripts within the batch are concluded. 

If anytime the user decides to close the batch via the mouse button ("X" on the upper right-hand side of the console) of if the batch crashes, "Script A" will, unfortunatelly, not be executed. 

How can I programatically intercept any moment of "X" and launch another batch to finalize the deed?

Kind regards,

Maleck
