1. You can prevent the user from clicking the abort or close by hiding them. Go to VI Properties>Window Appearance>Customize. Uncheck the options 'Show Abort button' and 'Allow user to close window'. You can modify the menu to remove the exit option.
2. You can trap the close and exit with an event structure and do your cleanup. There is a shipping example called Event Conditional Stop that you should look at.