protocol handler
Asked Answered
O

5

6

Requirement: We want to launch an external compare tool (like BeyondCompare or WinMerge) from a web page, through a button or link. The text file paths should be passed to the tool on its launch, so it understands them and opens them in the left and right side comparison panels.

Tried Solutions:

1) Using JavaScript's ActiveXObject: With this the user can simply click a button/link and launch the compare tool installed on its machine. But it works only in Internet Explorer, so we cannot go with this.

Ref: How to run an external program, e.g. notepad, using hyperlink?

2) Using Java Applet: Due to security reasons, applets embedded in a browser are not permitted to access the local file system and it will throw the "Access Control Exception". Hence, we cannot go with this too.

Ref: Why is my applet throwing an AccessControlException?

3) Using Protocol Handler: We can set up a custom URL protocol to trigger the program. Like how we've the mailto:[email protected] syntax used to create email links, this will automatically launches Outlook on Windows. "mailto" is a predefined protocol in Windows Registry.

Similarly we created our own protocol, say "launchCompareTool" in the registry and were able to launch any application like WinMerge or BeyondCompare. However, we're unable to achieve passing left and right side file paths as arguments to the application. May be the application getting launched need to expect these arguments.

Ref: 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 "body" and "subject" arguments passed to mail client (like Outlook), which understands them. These compare tools are not having such arguments that can be passed from protocol.

Is there another way we can meet this requirement?

Thanks, Abdul

Osyth answered 18/9, 2012 at 6:50 Comment(0)
W
2

Yet another approach recently coined to perform the same. Basically this new approach relays on creating a Handler application, which is nothing but a Windows console based ClickOnce application. The ClickOnce Handler application will acts as an interceptor between the Host (a web page or outlook or anything that can embedd the link) and the Target app (like WinMerge or Beyond Compare). The Handler application will be invoked on the click of the embedded link in the host application. The Link is nothing but a http url that will hold the information in the querystring parameter. Since the handler application is ClickOnce deployed so it allows itself to be publish to a Web server. The embedded link (HTTP URL) will invoke the handler application and then handler application will parse the received query string parameters and finally invoke the relevant target application. Handler application can be thought of as a Click Once Deployed parser application. Following is the detailed article with code example at Custom-HyperLinks-Using-a-Generic-Protocol-Handler.

Anshul Mehra

Whiteheaded answered 16/2, 2013 at 14:45 Comment(0)
T
1

The custom url can call a dos batch file or vbscript which parses the arguments and then calls winmerge.

Trilby answered 18/10, 2013 at 3:8 Comment(0)
T
0

I had a similar requirement wherein i needed to communicate with a desktop client from a browser app. The approach that i took was that of the Java Applet.

Soon enough i faced the exact same problem that you mentioned, i.e the "Access control exception" owing to security reasons. The correct way to handle this would be to SIGN an applet and you are good to go. These are the steps that i took to sign the applet of mine,

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
Talented answered 18/4, 2013 at 15:21 Comment(0)
J
0

Yes you can pass the parameters this way In html code do this

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

This will generate html as

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

It will pass your exe two parameters i.e. "alert:Hello" and "World". I am still searching for how to make first parameter only "Hello" without doing any parsing.

Jacquerie answered 24/4, 2015 at 7:32 Comment(0)
C
0

First I will present the requirements.

Then I will show you how to meet each of the requirements

Requirements:

  1. Create a small command line application that will take the target app path as parameter and after "?" will take arguments for the target application.
  2. Create a .reg file containing Custom URL registry information.
  3. Create a link for an application on your webpage with the Custom URL.

Let's get started:

  1. Creating the command line application: Steps:
    1. Open Microsoft Visual Studio and choose to create a new Console Application with Visual Basic template. We'll call it "MyLauncher".
    2. In project properties >> Application set target framework version to .NET 2.0 to make sure anyone will be able to use this app. C. Add reference to project - System.Windows.Forms D. Overwrite all the default code in your Module1.vb file to the following:

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, put it somewhere central, preferably on a network drive that everyone has access to.

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 reg key through your sysadmin central distribution or launch the .reg file on every PC.
B. Usage:
mylauncher:AppYouWantToLaunchPathGoesHere?ArgumentsGoHere

  1. Create a hyperlink on your webpage:
    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>
    


    Write to me if something doesn't work. I'll help you out.
    Best of luck friend.

Contorted answered 1/12, 2016 at 14:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.