Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is there some way to execute some piece of code before the computer shutsdown, logs off, hibernates or sleeps, with java?
I tried to use runlevel in a terminal in lubuntu, to try and listen for a 0, and if that happened, execute the code, but that did not work.
I also tried executing a joptionpane in shutdown, by listening for app exit, but that also did not work.
Can someone give me another advice?
Thanks.
Posted
Comments
Member 10850253 23-Apr-15 7:00am    
If I do this in c/c++, can I include that code in my java project, as an external library or something like that?
Member 10850253 23-Apr-15 7:37am    
Is it possible to send a signal to my java app, when a system shutdown, restart, logoff, sleep or hibernate occurs from an app made in c/c++?

1 solution

I do not think this is possible in pure Java. It is possible to do it in C/C++ by registering for certain messages in a Windows system. You need to check the Linux documentation to see if it provides a similar mechanism.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900