How can I tell if the system is being shutdown/restarted as at the moment my program blocks any kind of shutdown/restart unless you close it manually, so I need to tell it to close when this event occurs

Cheers
Tim