We use explorer /select command with the file path to open the file in windows explorer. https://support.microsoft.com/en-us/kb/152457 But on multiple invocations it opens a new window everytime. I am invoking the command from a java application using the process runtime APIs.
is it possible to have one window being opened ?. For e.g. if an explorer with c:/A is being opened ,repeated invocation of the same command must open the same window which is opened. ?
cheers
Saurav
It seems that your problem does not have a simple solution.
According to my understanding the "window sharing" of expplorer is not the explorer's feature. Please take a look on the following article: https://support.microsoft.com/en-us/kb/241911
(Although this article is talking about Internet Explorer I guess it is relevant for file exploerer as well).
According to my user experience the window sharing happens only when you are getting to directory via some kind of shortcut and does not happen when you are running explorer explicitly. For example if you type in "run" window "explorer" the new window is always created, however if you type "c:\" the window will be re-used.
You want to execute explorer with specific option, so you have to run it explicitly, therefore no window re-use can be achieved.
But I can suggest you 2 workarounds.
Do not use /select option. "Run" the base directory of the file you want to select. This will guarantee the window reuse. Then "select" file using java.awt.Robot by "typing" its name.
Manage the opened Explorer windows yourself into your java application. You can store map of file-to-exploerer window handler. When application wants to run open explorer for file that is already selected in other explorer window, activate it. To do this you need some JNI/JNA code. Take a look on the following discussions for details.
In Java Swing how do you get a Win32 window handle (hwnd) reference to a window?
Find out what application (window) is in focus in Java
Related
I'm using JNativeHook to detect drags and clicks outside a JFrame in my program and it's running perfectly. The thing is I need a way (either using JNativeHook or anything else) to check if a folder is opened in my explorer (Finder for Mac) so that I can move a file to this opened folder. JNativeHook doesn't seem to have the option of detecting on what program or window was the click made.
I expect the output of the code I'm looking for to return the path of open folders in my system explorer so that I can move files to this path.
You will not be able to detect if explorer is opened to a particular folder. There are API's to detect things like the window under the cursor and get information like the title, however, if explorer is not displaying the path in the title, it will be very hard to detect without traversing the application components and finding the address bar of the window. See WindowFromPoint and GetWindowTextA for a staring point. It should work fine under JNA and can be combined with the coordinates returned from JNativeHook.
I've made an application by java similar to notepad as a jar file then I make it exe file,,so what I want is to make this application appears in the right-click windows menu in the open with menu that can open for example any text file..
For example I have a text file on the desktop then when I right click on it and click open with my application should appear with the other available programs that can run this kind of files..
What should I do !
Windows has a thing called a "registry". It's an ancient and problematic system component that stores a wide range of data related to your computer, users, installed software, configuration and much more.
Part of the function of the registry is to associate file extensions (say, ".txt") with programs that can process files with that extension.
You've made an executable, and that's great. Now you need to tell windows that your executable can process files ending in certain letters. To do that you must modify the registry.
You could look into doing that with Java (there are answers here on SO) but I suggest that if your application is for consumption by other people, then the usual "done thing" on windows is to have an installer. My favourite is InnoSetup - free, fast, high quality.
Whichever tool you use (even a shell script) can set registry entries for you.
I've got a need to navigate java-applet programmatically and I am not that keen on Java platform. So lets assume I've got IE process stated with appropriate java applet loaded. Next I need to have some actions taken to this particular applet, like, lets say, sending WM_COMMAND to dialog along with BN_CLICKED code like I do with Windows in C. Assuming it's not a regular window I can refer to using HWND, I would like to ask someone for recommendations on how to do this.
As I understand you want to navigate (sending keystrokes and mouse clicks) a java-applet on the client side. It depends if you own the applet (say: you have the code and can change it) or if the applet is closed source and you just want to remote it.
In the first case use javascript to automate it. Change the containing HTML page to include some Javascript and pass parameters to the applet as described in the Java Tutorials.
If the applet accepts parameters, but you cannot change the HTML page, use a GreaseMonkey alternative for IE.
Your other approach (sending Windows Messages from an extern application to IE) should also work. Start Spy++ (use the 64bit version if you are using a 64bit Windows), choose "Search - Find window..." and drag the "Finder Tool" icon over the applet and release it. You will see then the HWND and if you press search you will see the window inside IE window hierarchy. So, yes you can send keystrokes and mouse clicks to a browser.
If I would automate the browser I would use Geb. You code a "web site test" in Groovy, just look at the Geb index page.
You could try to record a navigation through the applet with FireFox + "Selenium IDE" then export it and try run it in a Java Application with the Selenium IE WebDriver.
Information about Selenium can be found here : http://docs.seleniumhq.org/
Maybe this question will also help you : How to automate Java applet?
When I click on a link to "web start" my java application, browser downloads jnlp file which I should execute afterwards. Is there any way to force browser to execute jnlp right after the download completes, or event better, to make the whole process transparent, so user just confirms that he wants to launch the application? Thanks.
All you can do is provide the correct MIME type which in a standard setup makes the browser automatically open the file with Java WebStart.
Apart from that you cannot control whether the file is opened or not. Most browsers even have an option which prevents automatically opening downloaded files.
I am developing a Flex-based game, and struggling with SmartFox Server.
Anyway, it's a java-based server for Flash platform games, and it's kind of clunky to develop with on Windows. So, I want to be able to start it (and stop it) via Eclipse rather than the current batch file nastiness they provide.
The problem is I've never done that with a non-standard server that didn't just have a server adaptor in Eclipse.
I know it should be pretty simple, but how do I do it? It's really just a matter of calling a command line executable with some arguments, or even just running it as a Java application without its executable shell. Killing it would just be a matter of killing the process in Eclipse.
Also of note is that I want to make sure I have the shell output in Eclipse for debugging purposes.
I would think you could run it as an "External Tool" from Eclipse (the little green arrow with the toolbox). Click on the menu arrow to the right of that icon and select the "Configure External Tools" option.
You can then right click on the "Program" tree-node (on the Left hand side) and select "New" to create a new configuration. You will need to fill in the values similar to what you would do if you were running the server on the command line.
Give your configuration a meaningful name, like "SmartFox" or something.
Location is the command that is run (might point to java in your case).
To get the console setup, click on the "Common" tab and the "Allocate Console" checkbox should already be checked.
Once you are done, press the "Apply" or "Run" button.
You can then start the server by selecting it from the "External Tools" list (same icon as earlier) and you can stop it using the red stop icon on the console (should work).
Optional... the other tabs of the configuration dialog may be useful. You might want to have the build tab not do a build before launch, depending on how you have things set up.
What this wont give you (necessarily) is the tight integration between the server and Eclipse. You may have to do additional configuration or just deploy your code to the server as necessary.
Hopefully I am not way off base of what you were looking for.
Good luck.