Sure you can write a program to do anything in Outlook you want. It's just an application that offers objects and methods for any object oriented language you like.

But you can't run a program automatically at shutdown. But it's easy to write a batch file or something like it that runs your progra, then calls the system showdown function. Put it on your desktop and run it.