Forums Register Login

Detect windows shutdown

+Pie Number of slices to send: Send
Hi,

I want to gracefully exit my Java program that runs as a background service on windows shutdown. No Dialogs at shutdown announcing that This program must be exit... No computer hangups...

Can JACOB or JAWIN help me in this regard?

Thanx in Advance,

Maki Jav
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Thanks Valdo,

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.

Thanks once again.

Maki Jav
+Pie Number of slices to send: Send
What is wrong with using a shutdown hook?

Should your application really care if the system is being shut down, or just your application is being shutdown?
[ October 14, 2005: Message edited by: Michael Lloyd Lee ]
+Pie Number of slices to send: Send
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...



Maki Jav
I'm not dead! I feel happy! I'd like to go for a walk! I'll even read a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 4145 times.
Similar Threads
Making a command-line app "keep going"
Abnormal Termination
SHUT DOWN SYSTEM USING JAVA PROGRAM
URLyBird Server & DB shutdown
Hooking into the windows restart or shutdown commands
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 06:48:21.