2009-07-13 30 views
1

我在.NET MVC上構建了一個Intranet。我還在Winforms(性能選擇)中構建了一個單獨的規劃工具。我現在想從內聯網(IE7)「打開」規劃工具並傳遞參數(例如工作單號),以便我可以顯示該特定項目的計劃。這可能嗎?從網頁(intranet)執行.NET應用程序(no-install)並傳遞參數?

我有一個Winforms應用程序的.application文件。我也能夠改變.NET MVC Intranet和Winforms規劃工具上的所有內容。

回答

1

你不能簡單地從HTML調用應用程序;那將是一個安全漏洞。但是,您可以讓應用程序註冊表通過註冊表來處理這些請求。你說「不安裝」,所以這可能是一個問題。也許你的應用程序可能會在第一次加載時修改註冊表。

無論如何,應用程序將註冊處理特定的協議(如當你點擊itunes://或ftp://鏈接時)。

相反,你會碰到這樣的:

<a href="planning://3472">View workflow #3472</a> 

,然後用指定的參數啓動您的應用。

請參閱http://msdn.microsoft.com/en-us/library/aa767914(VS.85).aspx。你說IE7,但是一旦協議被註冊,這也應該與其他瀏覽器一起工作。

+0

我可以自己添加協議處理,這沒有問題。但是,在應用程序本身中沒有收到任何參數...即使我手動通過命令行運行它也不行。我只能執行MyApp.Application或Setup.exe,並且它們都不會將參數傳遞給實際的應用程序......? – Ropstah 2009-07-13 13:17:00

1

是的,你可以做到這一點。

private string _output = ""; 

public string Execute() 
{ 
    try 
    { 
     Process process = new Process(); 
     process.OutputDataReceived += new DataReceivedEventHandler(process_OutputDataReceived); 
     process.StartInfo.FileName = "path to exe"; 
     process.StartInfo.Arguments = "here you can pass arguments to exe"; 
     process.StartInfo.UseShellExecute = false; 
     process.StartInfo.RedirectStandardOutput = true; 
     Process currentProcess = Process.GetCurrentProcess(); 
     process.StartInfo.UserName = currentProcess.StartInfo.UserName; 
     process.StartInfo.Password = currentProcess.StartInfo.Password; 
     process.Start(); 
     process.BeginOutputReadLine(); 
     process.WaitForExit(); 
     return _output; 
    } 
    catch (Exception error) 
    { 
     return "ERROR : " + error.Message; 
    } 
} 
private void process_OutputDataReceived(object sender, DataReceivedEventArgs e) 
{ 
    if (e.Data != null) 
    { 
     _output += e.Data + Environment.NewLine;     
    } 
} 

這是一個簡單的例子。您可以使用不同的線程從exe中讀取輸出和錯誤。

+0

我需要啓動應用程序,而不只是讀取輸出。感謝努力。 +1 – Ropstah 2009-07-13 12:50:48

相關問題