從web啟動(dòng)winform程序
來(lái)源:程序員人生 發(fā)布時(shí)間:2015-01-18 10:07:04 閱讀次數(shù):2774次
最近有個(gè)客戶提出想從網(wǎng)站上啟動(dòng)1個(gè)客戶真?zhèn)€程序,研究了下,實(shí)現(xiàn)方法以下:
1. 注入注冊(cè)表
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啟動(dòng)參數(shù)設(shè)置失敗, 緣由: {0}", ex.Message));
}
注入后效果以下圖:

%1是傳入的參數(shù)
2. 網(wǎng)站上加1個(gè)link
<a href="HelloWorld://123">Hello World</a>
這里123是傳入的參數(shù)

當(dāng)我們點(diǎn)擊這個(gè)link時(shí),就會(huì)自動(dòng)打開(kāi)這個(gè)客戶端軟件。
生活不易,碼農(nóng)辛苦
如果您覺(jué)得本網(wǎng)站對(duì)您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈(zèng)