How to intercept Windows startup event in Swing - java

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.

Related

How to change windows desktop background

I realise that there are other questions on this topic, all of which I have attempted to implement the answers of and failed. I would like to end up with a full blown answer, ideally with a demonstration, on how to, in Windows and only Windows set the desktop background instantly without having the user log in and out or lock and log back in. The approach that involves using the runtime console to push the registry entries about and then rundll32 user32.dll call UpdatePerUserSystemPreferences has yet to work for me. The desired behaviour is achieved when the user right clicks an image file in explorer and selects 'Set as desktop background'. I'd like to do that programatically even if it devolves to the level of opening a hidden explorer window and right-clicking a file in it as long as the user sees nothing of it. The application in question updates the user's desktop background image with useful system information. The image to be used will be generated and regenerated every five seconds.
Can I change my Windows desktop wallpaper programmatically in Java/Groovy?
So the correct way is with JNA if you are not familiar with JNA or if you haven't used JNA the link above is for you. Otherwise you are right about using natives but you never stated how you are using them so I am just taking shots in the dark here.

Listener for when the user changes window (not necessarily windows created by the application)

I need to add a functionality in my application that would require me to know when the user changes window (it could be a browser window, my application's window or any other window).
Ideally, it should be possible for me to print the window's title when it gets focus. The problem I'm having finding a solution to this problem is that I only get links that tell me how to add a focus listener on windows I'm creating, which I already know how to do and doesn't help me in the slightest.
The solution should at least work on Windows 7.
The (major) problem you face is that Java filters system events so that you can only recieve events that are related to you. AFAIK this is all done at a native level, so there's no way to intercept or modify this filtering process.
The only solution is to create another "event loop" using JNI/JNA which will allow you to intercept the event messages being passed about the system and handle them the way you want to.
While slightly more complicated, it does open up a world of opportunities...

How to keep taskbar bottom of other windows?

I try to make an application which must be full screen. But when i press CTRL+ALT+DEL task manager comes up. Even i disable task manager, at this time its error message comes up and make taskbar visible. Then user get the chance to go to the dekstop but i dont want user to get this chance. Only user could be able to go to desktop when it did what application wants from it. So i need taskbar keep bottom of other windows until user does what it should do. And i need to do this by my application which i try to code in Java
How can i change the status of task bar using registry?
Why not permanently disable the taskbar?
Follow this link to permanently disable the task bar.
You can edit .reg files in Java, follow This link to know how to edit .reg files
"But how can i do it by java without reseting the machine?"
As far as i came across, you have to reboot your system, no way out.
Ok i found it.
When i changed the value of 8th byte value of Settings variable to 10 in
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects2
in registery
It just deselect the "Keep the task bar on top other windows" option
For applying the changes explorer.exe should be killed and re run
There are key strokes which Windows catches before they are sent to application and Ctrl+Alt+Del is one of those.
Regarding "Then user get the chance to go to the dekstop", if you set frame.setAlwaysOnTop(true);, user won't be able to switch to other any application.
You can use java's fullscreen API, and then use a Robot to force focus back to your application. See here: Java Full Screen Program (Swing) -Tab/ALT F4.
Good luck in whatever you are doing - it doesn't sound fun!

How to Hide Task Manager's Error Message Dialog Box When Task Manager is Disabled

Hi i try to make a program with java which must be full screen and always on top. However, when i press CTRL + ALT + DEL task manager comes up. I blocked Task Manager by editing regedit values but now its error message dialog box "Task Manager has been disabled by your administrator" comes up
How can i hide that dialog box?
I don't think this is possible in Java, and in fact I don't know that you can (or want to) do it in general. The "always on top" layer on Windows contains a stack of windows just like the "user" layer, and you don't normally (and should not) have control over those other programs. If any one program could take over the entire machine and block anything, even the operating system, from appearing for the user, that would be disturbing...

'Open With' Dialog

I making an app in Java. I want an Open With Dialog to appear when a JButton is clicked.
I know that in Windows, the contents of the Recommended Programs list are determined from the registry entry
HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\filetype\OpenWithList
..where 'filetype' is the required file type.
Is there any way that this can be done with complete independence of the OS in which this app runs? Or do I have to get the OS name and program accordingly?
Not completely sure whether this answer will be relevant as I am making some assumptions. In case it is a file you want to open, you can use Desktop#open which will open the File with the default application.
I assume (but did not test) that when no default application is set, a dialog will be shown asking what application you want to use to open that file (similar as when you double click such a file in your file browser).
This is not completely what you asked for, but might be sufficient.
Otherwise I am afraid I agree with Andrew's answer that there is no general way to do this.
Is there any way that this can be done with complete independence of the OS in which this app runs?
No.
Or do I have to get the OS name and program accordingly?
Yes.

Categories

Resources