国内最全IT社区平台 联系我们 | 收藏本站
华晨云阿里云优惠2
您当前位置:首页 > php开源 > php教程 > 从web启动winform程序

从web启动winform程序

来源:程序员人生   发布时间:2015-01-18 10:07:04 阅读次数:2571次

最近有个客户提出想从网站上启动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));
}

注入后效果以下图:

image

%1是传入的参数

2. 网站上加1个link

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

这里123是传入的参数

image

当我们点击这个link时,就会自动打开这个客户端软件。

生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠
程序员人生
------分隔线----------------------------
分享到:
------分隔线----------------------------
关闭
程序员人生