Ok, here is what I am thinking.
A. Netbeans I believe uses a bit of JNI for this hook. I am installing Netbeans right now because I can't remember. If this is the case, you will have to look into JNI and some Win32 API to figure out how this is done. So, pretty much out of the scope of this forum.
B. If the application is responding ok why on earth would you kill the system process instead of just closing the app? If you are trying to cover all possiible closing issues and the saving of documents, I wouldn't waste my time. If the user is dumb enough to "End Task" or "kill" the running process when they could have just as easily closed it the proper way, then that's their problem. Not ours as developers to compensate for.
I'll let you know what I figure out after I install Netbeans.