I created a JFrame
with a few labels. I need to display a JOptionPane
with the message "welcome user" once. If the frame is re-opened before rebooting Windows, the JOptionPane
should not appear, but if Windows is rebooted, the JOptionPane
should appear again.
How am I able to detect whether the system has been rebooted, since the last time my application ran?
So, as @Kayaman mentioned, there isn't an isRebooted()
method in Java... but you can make one.
Assuming you are working on Windows platforms (you would need to implement a separate version for other OSes), you could query the system event log . With all the stuff that gets put in there I reckon it would include an event for "logged in", so all you need to do is find a way to look up the last "logged in" time and see if it has changed since the last time you checked.
Accessing the event log is a windows specific trick, and so won't be in the native java api, however there is a question on how to access the event log from Java which you could use as a base.
Drop a BAT script in the Autostart folder of the user which creates a file in a specific location:
echo JUST_STARTED > C:\NAME_OF_YOUR_APP.TXT
In your app, check whether the file exists. If it does, delete it and display the message.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.