I've written a program in Java using JNA so I can also execute C code.
The program launches a JFrame, makes sure the window is on top and then takes a screenshot of the window (using PrintWindow of user32.dll). It saves the screenshot as a jpg and quits.
It works when I'm logged in and starts the program myself. My problem is that I want the program to run by itself on Windows Server 2000 at certain times when I'm not logged in. It appears that Windows does not bother to render the window content when that happens, the window title and borders appears but the content of the Window is black.
Does anyone know how to fool Windows into thinking that I'm logged in and has focus on the JFrame so it actually renders the content? Launching some sort of desktop emulator that in turn starts my program would be acceptable.
Footnote (offtopic): Please make it so that I can ask questions without having to make an account again. It is bothersome and makes Internet a worse place.
Related
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.
I have an applet code. That i added to one of my web-application, when i click tab called Enrollment, applet will load and java console will open. it is happening.
And when i click other tab this java console has close. and again if i click Enrollment tab again new Java console has open.
How to do it please help me regarding this.
How to close java console in mac when page get navigates to other page.?
The console disappearing is subject to decisions by the JVM. Typically it will be left on-screen as long as the JVM runs, and that is significantly later than when the user navigates away from the page.
The console can be configured (by the user or their system administrator) to not show at all. Anything beyond visible/not visible is not open to our control and you should not worry about, it is just wasting time.
I have an applet packaged with a third part dll (from JTwain). My applet scans documents from the TWAIN compatible default printer. The applet fails on a paper jam and won't recover. The user navigates away from the page and the applet is destroyed. When returning to the page it fails again. Closing the browser (which kills java.exe process on the pc), and then returning to the page clears the problem and everything works.
I want to restart everything without requiring users to close down the browser. I've added a GUID query string to the URL's from which the applets resources are loaded - so I know nothing is being cached. I've checked in the windows task manager and there is no process created by the dll, it's all happening within the main java.exe process. I tried wrapping the scanning process in a thread so I could interrupt it in the stop or destroy methods (just in case the applets thread weren't stopped when the applet was destroyed), but that didn't work.
Any suggest would be greatly appreciated. Ideally I'd like some way to restart java when the applet unloads (but I doubt that's possible).
UPDATE
I've spent a couple of days trying to identify what causes the applet to fail. I still don't know :(
When the paper jam occurs something (not my code), is producing a couple of popups. The first alerts the user of the jam, and can be closed by clicking the OK button. The second says 'reading from device' and hangs. It cannot be close with the red, close window, icon in the top corner - I kill it from the task manager and windows asks to send a report regarding the 'non-responsive program'. I assume these popups are produced by the dll. And given that the second hangs, my assumption is that a thread started by the dll has hung while retaining a lock on some component of the TWAIN application. I get
com.asprise.util.jtwain.JTwainException: Failed to open the specified data source:
Source: TW-Brother MFC-9970CDW LAN Thrown
..when I try to access the scanner.
I'm at a bit of a loss as to how I can get more information. I'm testing my applet on a windows virtual pc (so as to use ie7), and don't have a method for step debugging in this environment. (And it's crashing on third party code for which I have no source anyway)
I see only two practical options here:
Use an API that handles paper jam without problems. Of course, that is easy to say (get robust API), harder to find.
Launch the app. free floating using Java Web Start. If it freezes up, the user can kill it and click the link for another instance in a new JVM. Or the applet might also call BasicService.showDocument(URLof.jnlp) if it can detect a problem with the DLL and is not itself frozen.
Of course, you should also report the bug to the ..Asprise(?) developers. The optimal solution would be to have the problem fixed at its source. Anything we do here is a 'workaround'.
The goal is to have the user select a java program, then my program opens up a JInternalFrame with a JEditorPane inside it as the console and places said JInternalFrame in a JDeskopPane. Is it possible to change all the Windows the user's program may open into JInternalFrames and place them in said JDesktopPane, as well?
(individual question from IDE-Style program running)
I'm quite sure that this would not be possible to do without tampering with the binaries of the program that you're launching. If the target program performs something like new Window().show(), you'll have little possibilities to "hook into" the system, and tell it to swap it for a JInternalFrame.
What I'm saying is that if the program is written and compiled to show a top-level window, there is little you could do to change that. There is no "hook" into the system, with which you can say "put all future Windows into this JInternalFrame.
Is it possible to get image contents of an obstructed window without bringing it to the front? Also, is it possible to send mouse clicks to a specific locations of such window? I want to do this in Java, using JNA, running Windows XP (if it is possible, would it also work on Windows 7?). If that can be done, would you mind telling me what functions will be needed and where can I read about it, because I have never worked with JNA yet. Thank you.