2012-09-18 119 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> 
    


    寫對我來說如果有什麼不行的話。我會幫你解決的。
    祝你好運的朋友。