從web啟動winform程序


最近有個客戶提出想從網站上啟動一個客戶端的程序,研究了下,實現方法如下:

1. 注入注冊表

      try
                {
                    string appPath = "\"" + Application.ExecutablePath + "\" \"%1\"";
                    string strKey = Application.ProductName;
                    string strKey_shell_open_cmd = strKey + @"\shell\open\command";
                    var subKey = Registry.ClassesRoot.CreateSubKey(strKey);
                    subKey.SetValue("URL Protocol", "1");
                    var subKey_shell_open_cmd = Registry.ClassesRoot.CreateSubKey(strKey_shell_open_cmd);
                    subKey_shell_open_cmd.SetValue(null, appPath);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(string.Format("Web啟動參數設置失敗, 原因: {0}", ex.Message));
                }

 

注入后效果如下圖:

image

%1是傳入的參數

 

2. 網站上加一個link

<a href="HelloWorld://123">Hello World</a>

這里123是傳入的參數

 

image

 

當我們點擊這個link時,就會自動打開這個客戶端軟件。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM