從web啟動winform程序
來源:程序員人生 發布時間:2015-01-18 10:07:04 閱讀次數:2780次
最近有個客戶提出想從網站上啟動1個客戶真個程序,研究了下,實現方法以下:
1. 注入注冊表
try
{
string appPath = """ + Application.ExecutablePath + "" "%1"";
string strKey = Application.ProductName;
string strKey_shell_open_cmd = strKey + @"shellopencommand";
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));
}
注入后效果以下圖:

%1是傳入的參數
2. 網站上加1個link
<a href="HelloWorld://123">Hello World</a>
這里123是傳入的參數

當我們點擊這個link時,就會自動打開這個客戶端軟件。
生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈