2012-09-18 122 views
4

要求:我们希望通过按钮或链接从网页启动外部比较工具(如BeyondCompare或WinMerge)。文本文件路径应该在其启动时传递给工具,以便理解它们并在左侧和右侧比较面板中打开它们。协议处理程序

试图解决

1)使用JavaScript的ActiveXObject的:有了这个用户只需点击一个按钮/链接并启动安装了机器上的比较工具。但它只适用于Internet Explorer,所以我们不能这样做。

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

2)使用Java小程序:由于安全方面的原因,小程序嵌入在浏览器不允许访问本地文件系统,它会抛出“访问控制异常”。因此,我们也不能这样做。

编号:Why is my applet throwing an AccessControlException?

3)使用协议处理程序:我们可以设置自定义URL协议触发程序。就像我们用mailto:[email protected]语法来创建电子邮件链接一样,这会自动在Windows上启动Outlook。 “mailto”是Windows注册表中的预定义协议。

同样,我们创建了自己的协议,在注册表中说“launchCompareTool”,并且能够启动任何应用程序,如WinMerge或BeyondCompare。但是,我们无法实现传递左侧和右侧文件路径作为应用程序的参数。可能是启动的应用程序需要期待这些论点。

价: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

不同于“电子邮件地址”协议,其具有“身体”和“受试者”参数传递给邮件客户端(例如Outlook),其理解它们。这些比较工具没有可以从协议传递的参数。

有没有另外一种方法可以满足这个要求?

感谢, 阿卜杜勒

回答

2

另一种方法最近创造的执行相同。基本上,这种新方法继承了创建Handler应用程序的功能,它只是一个基于Windows控制台的ClickOnce应用程序。 ClickOnce Handler应用程序将充当Host(网页或Outlook或任何可嵌入链接的内容)与Target应用程序(如WinMerge或Beyond Compare)之间的拦截器。 Handler应用程序将在主机应用程序中的嵌入式链接点击时被调用。链接不过是一个http url,它将保存querystring参数中的信息。由于处理程序应用程序是ClickOnce部署的,所以它允许自己发布到Web服务器。嵌入式链接(HTTP URL)将调用处理程序应用程序,然后处理程序应用程序将解析接收到的查询字符串参数并最终调用相关的目标应用程序。 Handler应用程序可以被认为是Click Once Deployed解析器应用程序。以下是代码示例的详细文章,内容为Custom-HyperLinks-Using-a-Generic-Protocol-Handler

Anshul梅拉

0

我也有类似的要求,其中,我需要与从浏览器应用程序桌面客户端进行通信。我采用的方法是Java Applet。

很快我就遇到了你提到的完全相同的问题,即由于安全原因导致的“访问控制异常”。正确的方法来处理这将是SIGN一个小程序,你很好去。 这些是我把签我的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 
1

定制URL可以调用DOS批处理文件或VBScript其解析这些参数,然后调用的WinMerge。

0

是的,你可以传递参数这样 HTML代码中做到这一点

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

这将生成HTML作为

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

它会把你的EXE的两个参数,即“警报:你好“和”世界“。 我仍然在寻找如何仅做第一个参数“Hello”而不做任何解析。

0

好的,这将会长时间与我在一起。
首先我将介绍这些要求。
然后我会告诉你如何满足每一项要求
要求:“?”
1.创建一个将目标应用程序路径作为参数,后一个小命令行应用程序将为目标应用程序提供参数。
2.创建包含自定义URL注册表信息的.reg文件。
3.使用自定义URL为您的网页上的应用程序创建链接。

让我们开始吧:
1.创建命令行应用程序:
步骤:
A.打开Microsoft Visual Studio,并选择创建一个新的控制台应用程序使用Visual Basic的模板。我们将其称为“MyLauncher”。
B.在项目属性>>应用程序设置目标框架版本到.NET 2.0,以确保任何人都可以使用这个应用程序。
C.添加参照项目 - System.Windows.Forms的
D.覆盖所有默认的代码在你的Module1.vb文件到以下几点:
代码:

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.编译程序。并在本地进行测试后,将其放置在中央的某个位置,最好放在每个人都可以访问的网络驱动器上。

2.创建一个。包含下面的代码reg文件:
代码:

 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.通过你的系统管理员分发中心分发了reg键或启动每台PC上的.reg文件。
B.用法:
mylauncher:AppYouWantToLaunchPathGoesHere ArgumentsGoHere

  • 创建网页上的超链接:
    代码:

    <!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> 
    


    写对我来说如果有什么不行的话。我会帮你解决的。
    祝你好运的朋友。