I had similar problem with a Java proxy server. I solved it by creting an empty invisible AWT window, calling pack() on it and adding WindowListener to it. It will receive windowClosing event on windows shutdown.
I seems that on Windows, a window is requires even for some nonGUI tasks. Maybe that's why the OS is called Windows.
Joined: May 09, 2002
Following ur idea I have come up with this class
I am writing messages to a file in that method of TestRunMethod class.
This class is working for windows 98 ie when I logoff, restart or shutdown
This class will be helpful to others too.
Batch file running this has code
C:\jdk1.3\bin\javaw.exe TestAwtWindow EXIT
So when windows is exiting no command prompt is present to halt it on the way.
The problem with shutdown hook is that I could get it respond to user using CTRL + C keys on a command prompt window running my java app. It did not do anything if user closes it by clicking on X (close). What if my non gui java app is running invisibly?
My application has to do some things on system shutdown...
ShutdownHook does not respond to system shutdowns...