Protocol handler

Requirement . We want to launch an external comparison tool (for example, BeyondCompare or WinMerge) from a web page using a button or link. The paths of text files must be transferred to the tool when it is run, so it understands them and opens them in the left and right comparison panels.

Tried Solutions :

1) Using JavaScript ActiveXObject : in this case, the user can simply click the button / link and launch the comparison tool installed on his machine. But it only works in Internet Explorer, so we cannot go with this.

Link: How to run an external program, for example. notepad using a hyperlink?

2) Using a Java applet . Due to security concerns, applets embedded in the browser are not allowed to access the local file system, and this will result in an “access control exception”. Therefore, we, too, cannot handle this.

Link: Why is my applet throwing an AccessControlException?

3) Using a protocol handler . We can configure our own URL protocol to run the program. Just as we use the mailto: user@email.com syntax used to create email links, it will automatically launch Outlook on Windows. "mailto" is a predefined protocol in the Windows registry.

In the same way, we created our own protocol, for example, "launchCompareTool" in the registry and were able to launch any application, such as WinMerge or BeyondCompare. However, we cannot get left and right file paths as arguments for the application. Maybe the launch of the application should expect these arguments.

Link: http://www.dreamincode.net/forums/topic/220444-run-program-from-server-on-client-computer/ http://msdn.microsoft.com/en-us/library/aa767914% 28v = vs. 85% 29.aspx # app_reg

Unlike the mailto protocol, which has the "body" and "subject" arguments passed to the mail client (for example, Outlook), which understands them. These comparison tools do not have arguments that can be passed from the protocol.

Is there any other way to satisfy this requirement?

Thanks, Abdul

+4
source share
5 answers

Another approach recently came up with to accomplish the same thing. Basically, this new approach allows you to create a Handler application that is nothing more than a ClickOnce application based on the Windows console. The ClickOnce Handler application will act as an interceptor between the host (a web page or Outlook, or one that can insert a link) and the target application (for example, WinMerge or Beyond Compare). The Handler application will be invoked by clicking on the embedded link in the main application. A link is nothing more than an http-url that will store information in the querystring parameter. Because the handler application is deployed by ClickOnce, it therefore allows you to publish it to a web server. A nested link (HTTP URL) will call the handler application, and then the handler application will analyze the received query string parameters and, finally, will call the corresponding target application. The handler application can be thought of as the "Click Clicked Deployed Deployed Parser" application. The following is a detailed article with sample code in the Custom-HyperLinks-Using-a-Generic-Protocol-Handler .

Anshul Mehra

+2
source

A custom url can invoke a dos or vbscript batch file that parses the arguments and then calls winmerge.

+1
source

I had a similar requirement in which I needed to communicate with the desktop client from a browser application. The approach I took was the Apple Java approach.

Soon enough, I ran into the same issue that you mentioned, that is, “access control exception” due to security concerns. The right way to handle this would be with the SIGN applet, and you're good to go. These are the steps I took to sign my applet,

javac MyClient.java jar cvf MyClient.jar MyClient.class keytool -genkey -validity 3650 -keystore pKeyStore -alias keyName keytool -selfcert -keystore pKeyStore -alias keyName -validity 3650 jarsigner -keystore pKeyStore MyClient.jar keyName 
0
source

Yes, you can pass parameters like this In html code do this

"<a href='alert:\"Hello World\"'>this link</a>"

This will create html like

<a href="alert:"Hello World"">this link</a>

It will pass two parameters to your exe, that is, "alert: Hello" and "World". I'm still looking for how to make the first parameter only “Hi” without doing parsing.

0
source

Well, it will be as long as I am. I will introduce the requirements first.
Then I will show you how to fulfill each of the requirements of the Requirement:
1. Create a small command-line application that will accept the target application path as a parameter after "?" will accept arguments for the target application.
2. Create a .reg file containing the registry information for the user URL.
3. Create a link for the application on your web page using a custom URL.

Let's start:
1. Creating a command line application:
Stages:
A. Open Microsoft Visual Studio and choose to create a new console application with a Visual Basic template. We will call it "MyLauncher".
B. In the project properties -> Application set target framework version to.NET 2.0 to make sure that someone can use this application.
C. Add Project Link - System.Windows.Forms
D. Overwrite all the default code in the Module1.vb file as follows: Code:

  Imports System.IO Imports System.Threading Imports System Imports System.Windows.Forms Module Module1 Dim array As String() Sub Main() Dim origCommand As String = "" Dim sCommand As String = Command().ToString If String.IsNullOrEmpty(sCommand) Then Application.Exit() End If origCommand = sCommand origCommand = origCommand.Substring(origCommand.IndexOf(":") + 1) origCommand = origCommand.Split("""")(0) execProgram(origCommand) End Sub Private Sub execProgram(ByVal sComm As String) Try Dim myPath As String = Nothing Dim MyArgs As String = Nothing Dim hasArgs As Boolean If sComm.Contains("""") Then sComm = sComm.Replace("""", "").Trim() End If If sComm.EndsWith("?") Or sComm.Contains("?") Then hasArgs = True MyArgs = sComm.Substring(sComm.IndexOf("?") + 1) myPath = sComm.Substring(0, sComm.IndexOf("?")) Else myPath = sComm End If If hasArgs Then startProg(myPath, MyArgs) Else startProg(myPath) End If Catch ex As Exception Dim errMsg As String = sComm & vbCrLf & vbCrLf & "The program you are trying to launch was not found on the local computer" & vbCrLf & vbCrLf & vbCrLf & "Possible solutions:" & vbCrLf & vbCrLf & "If the program doesn;t exist on the computer, please install it. " & vbCrLf & vbCrLf & "If you did install the program, please make sure you used the provided default path for istallation. " & vbCrLf & vbCrLf & "If none of the avove is relevant, please call support" & vbCrLf & vbCrLf If ex.Message.Contains("The system cannot find the file specified") Then MessageBox.Show(errMsg, "System Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign) Else MessageBox.Show(ex.Message, "Default Error", MessageBoxButtons.OK) End If End Try End Sub Private Sub startProg(myPath As String, Optional MyArgs As String = "") Try Dim proc As Process If Not String.IsNullOrEmpty(MyArgs) Then proc = New Process() proc.EnableRaisingEvents = False proc.StartInfo.FileName = myPath proc.StartInfo.Arguments = MyArgs proc.Start() Else proc = New Process() proc.EnableRaisingEvents = False proc.StartInfo.FileName = myPath proc.Start() End If Catch ex As Exception End Try End Sub End Module 

E. Compile the program and after testing it locally, place it somewhere in the center, preferably on a network drive to which everyone has access.

2. Create a .reg file containing the following code:
Code:

  Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\mylauncher] "URL Protocol"="\"\"" @="\"URL: mylauncher Protocol\"" [HKEY_CLASSES_ROOT\mylauncher\shell] [HKEY_CLASSES_ROOT\mylauncher\shell\open] [HKEY_CLASSES_ROOT\mylauncher\shell\open\Command] ;example path to the launcher is presented below. Put your own and mind the escape characters that are required. @="\"\\\\nt_sever1\\Tools\\Launcher\\BIN\\mylauncher.exe\" \"%1\"" 

a. Distribute the registry key through the central sysadmin distribution or run the .reg file on each PC.
B. Use:
mylauncher: AppYouWantToLaunchPathGoesHere ArgumentsGoHere

  1. Create a hyperlink on your web page:
    Code:

      <!doctype html> <html> <head> </head> <body> <div class="test-container"> <a href='mylauncher:C:\Program Files\IBM\Client Access\Emulator\pcsfe.exe?U=MyUserName' >TEST</a> </div> </body> </html> 


    Email me if something is not working. I will help you.
    Best friend of luck.

0
source

Source: https://habr.com/ru/post/1434769/


All Articles