Launch an Application from a Browser - java

I would like to have a link or button on my web site that launches
vim (an editor) on a specific file (e.g., myfile.txt) on my local machine.
I want to launch C:\Vim\Vim74\gvim.exe on C:\Users\paulco\myfile.txt form any browser.
I want this to work on all (realistically most) browsers.
I actively use Chrome, Opera, FireFox and IE (in that order of preference).
In order for it to work across all of these browsers,
I think the script has to Java-based.
Does anyone know how to do this?
Does anyone have a Java-based script that does this?
Here are some resources I found on the topic.
But either they are IE specific or don't work.
Launch application from a browser
http://msdn.microsoft.com/en-us/library/aa767914%28VS.85%29.aspx

I have tested the following on Internet Explorer, Chrome, Opera and Firefox.
The browser has to run on a Windows operating system, Linux and Mac require different aproaches.
Solution is to define a protocol handler for a custom protocol.
1) Take this HTML example, it should open the specified text file using notepad.exe:
Open Textfile
2) You need to define the protocol handler in the windows registry, save the following to a file named testing.reg and execute it (double click on it), or enter the values manually using regedit:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\test]
#="URL:Editor test"
"URL Protocol"=hex(2):00,00
[HKEY_CLASSES_ROOT\test\DefaultIcon]
#="\"C:\\Windows\\system32\\notepad.exe\""
[HKEY_CLASSES_ROOT\test\shell]
[HKEY_CLASSES_ROOT\test\shell\open]
[HKEY_CLASSES_ROOT\test\shell\open\command]
#="\"C:\\temp\\editor.bat\" %1"
3) As you can see, I am not calling notepad.exe directly, but a c:\temp\editor.bat batch file. This is because the file-parameter has to be modified. using the %1 as a parameter will pass the complete URL including the test: custom protocol name to the shell. In the script, I use a simple substring pattern to extract the specified file name and call the editor:
REM editor.bat
set param=%1
notepad %param:~5%
That's all!

Related

Registering a java application as the default browser in Windows 10

I am writing a java application, which can handle standard links (http/https).
How can I register my application as the default program opening these links (aka default browser) in Windows 10?
I know I can select the default browser in the windows settings, but it only shows a limited list, no way to hook up a custom program.
I've found this, but it only shows how to do it pre-win10, plus I'm not sure it can be done in java.
The application needs to be packaged as an exe.
I used launch4j for this. Make sure textVersion and icon is set.
A lot of registry keys need to be created. I've pieced those together by looking at this post (kindly linked by #Tarun Lalwani), this post, and the registry entries created by firefox. This means some of them might not be necessary.
Register client
[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\MyApp\Capabilities]
'ApplicationDescription'='MyApp'
'ApplicationIcon'='C:\MyApp\MyApp.exe,0'
'ApplicationName'='MyApp'
[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\MyApp\Capabilities\URLAssociations]
'http'='MyAppURL'
'https'='MyAppURL'
[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\MyApp\DefaultIcon]
#='C:\MyApp\MyApp.exe,0'
[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\MyApp\shell\open\command]
#='C:\MyApp\MyApp.exe'
Register url handler
[HKEY_LOCAL_MACHINE\Software\Classes\MyAppURL]
#='MyApp Document'
'EditFlags'=0x2
'FriendlyTypeName'='MyApp Document'
'URL Protocol'=''
[HKEY_LOCAL_MACHINE\Software\Classes\MyAppURL\DefaultIcon]
#='C:\MyApp\MyApp.exe,0'
[HKEY_LOCAL_MACHINE\Software\Classes\MyAppURL\shell]
#='open'
[HKEY_LOCAL_MACHINE\Software\Classes\MyAppURL\shell\open\command]
#='"C:\MyApp\MyApp.exe" --url "%1"'
Register to default programs
[HKEY_LOCAL_MACHINE\SOFTWARE\RegisteredApplications]
'MyApp'='Software\Clients\StartMenuInternet\MyApp\Capabilities'
Now the application can be selected in the windows settings

Disable message print on terminal when using Desktop.browse

I'm developing a command line tool and at some point it redirects the user to the default web browser. I use the following code for that
if(Desktop.isDesktopSupported()){
Desktop.getDesktop().browse(new URI("http://www.example.com"));
}
The browser opens without any problem but there are some messages printed on the console while this is up. stuff like
[6620:6620:0622/180058:ERROR:browser_window_gtk.cc(1082)] Not implemented reached in virtual void BrowserWindowGtk::WebContentsFocused(content::WebContents*)
or
Created new window in existing browser session.
Is there a way to stop printing these kind of messages. (as it is a command line application it does not look good). Is there any other way to open a browser?
Thanks in advance
This looks like this is printed by the browser on startup. These GTK log messages aren't uncommon.
You can start the browser directly from the console to verify this.
EDIT:
As starting the browser is handed off to an operating system specific method, there's not much control over it.
To have better control you can try to launch the browser directly:
launch the process Launch JVM process from a Java application use Runtime.exec?
for linux (more or less cross-distribution): Linux: command to open URL in default browser
for windows: Launching a website via windows commandline
You can use Desktop.browse if the other methods fail.

How to launch client machine exe file and not dependent on browser?

I want to launch a exe file when click on the button from my appliction and that should be from client machine. I tried with following solutions.
Runtime.getRuntime().exec(".....\\somefile.exe");
when I follows the above solution then it was opened server machine exe file.
I applied one more solution in script code
i.e
**var ws = new ActiveXObject("WScript.Shell");
ws.Exec("...\\somefile.exe");**
the above code working fine but I need to enable ActiveX related script enble mode in client browser window manually and it is only applied for IE only.
Let me know any solution that is browser independent and without activex enable option.

Integrating Autoit to selenium: Getting value of variable in AutoIT code in Selenium script

My requirement is to automate configuring an instance(instance of my company product I am working on). The scenario is such that in the middle of my configuration, the control goes from window to browser and the rest of the configuration process is handled in the browser and so the entire process is a combination of window-based and browser-based. I have used AutoIT to complete the window-based configuration and when the control goes to the browser, I am using _FFStart() $ffUrl = _FF_GetCurrentURL(). I am getting the URL in a variable in AutoIT script. I want to automate the further web-based configuration through Selenium. I am calling this AutoIT compiled script from my Java class.
My question is that is there a way in which I can get the URL that I am saving in my AutoIT script so that I can create a web driver instance, open the browser with the URL and further handle my configuration process using Selenium.
if you start/run an exe file from your code you can path variable as argument
something like:
$va = "my variable"
run("myexe.exe $var)
or equvivalent
or generally:
You can share variables between appliations/processes many ways
using windows messaging look up _WinAPI_PostMessage function that sends message the specific window or broadcast message to all windows so all running app gets the message (2 variables can also be passed) in autoit you can set up a function that runs (stoppping the main program) when your autoit app receives such message and variables
you can set up UDP or TCP channels so that your running apps can communicate (UDP should work fine) one app being the server the other is the client
file communication setup, where the variable or information to be sent is written to a file and the other app reads the file (it can be good to combine with the first method: App 'A' writes data to file 'data.msg' then sends message to App 'B' that upon receiving the message reads 'data.msg') you can establsih intricate protocol as well with Acknowladge messages etc. in case your application requires it.
_WinAPI_RegisterWindowMessage
_WinAPI_PostMessage
GUIRegisterMsg
are the relevant functions you can look them up in autoit help
If you think any of these is feasible but you need further assistance I can write a simple code that demonstrates that in practice

How we can open browser through j2me code in ubuntu os?

How we can open browser through Java ME code in ubuntu os ?
I am using the below given code
String URL1="any url";
midlet.platformRequest(URL1);
The above line does not open the browser in the UBUNTU 10.10 but its working fine on windows os.
Please help me if any body else have faced the same problem.
if you use emulator (which one?), check if it is properly configured (emulators tend to have stuff like that in User Guide y'know)
eg this article provides a recipe for WTK / ME SDK:
...The J2ME Wireless Toolkit supports the platformRequest() method, but
before using the method you must tell the toolkit what to do when it's
invoked. You can associate only one platform service with
platformRequest(). For instance, if for testing purposes you associate
the method with your browser, the browser will be launched every time
you call platformRequest(). If you need more flexibility, you can
associate platformRequest() with a script that will use the URL
scheme to route the request to the right handler.
To associate a particular platform service with platformRequest(),
simply add a com.sun.midp.midlet.platformRequestCommand attribute to
the system.config file in the toolkit's lib directory. For example, to
invoke the Mozilla browser whenever platformRequest() is called, add
the following to system.config:
# Associate the Mozilla browser with platformRequest() - Windows
com.sun.midp.midlet.platformRequestCommand: "C:\Program Files\mozilla.org\Mozilla\mozilla.exe"
Given this setting, the call
platformRequest("http://developers.sun.com/mobility") will launch
Mozilla, and the browser will navigate to Sun's developer mobility
portal...

Categories