um im not sure of the practicality of this solution, but could you not have your app running in the background and use the queryunload event to catch the system shutdown?!?
you may need the abortsystemshutdown api to stop windows actually shutting down, im not sure!?
then when your code has executed use the initiatesystemshutdown api.
just an option, but i imagine there will be a much simpler solution somewhere!!
good luck If somethings hard to do, its not worth doing - Homer Simpson