目的:
类似迅雷一样,当点击页面链接(迅雷支持的链接比如:thunder://…)的时候自动打开迅雷下载
准备winform代码:
新建一个winform应用程序,在program.cs中添加几行代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace WindowsFormsApp7
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
for (var i = 0; i < args.Length; i++)
{
MessageBox.Show(args[i]);
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
编译完成后将生成的exe程序拷贝至D盘根目录下:
准备修改注册表的脚本:
reg add HKEY_CLASSES_ROOT\test /v "URL Protocol" /t REG_SZ /d "D:\\WindowsFormsApp7.exe" /f
reg add HKEY_CLASSES_ROOT\test /ve /t REG_SZ /d "测试程序" /f
reg add HKEY_CLASSES_ROOT\test\DefaultIcon /ve /t REG_SZ /d "D:\\WindowsFormsApp7.exe,1" /f
reg add HKEY_CLASSES_ROOT\test\shell /f
reg add HKEY_CLASSES_ROOT\test\shell\open /f
reg add HKEY_CLASSES_ROOT\test\shell\open\command /f
reg add HKEY_CLASSES_ROOT\test\shell\open\command /ve /t REG_SZ /d "\"D:\\WindowsFormsApp7.exe\" \"%%1\"" /f
注意:执行的时候以管理员身份运行,运行结果如下:
此时检查window注册表:
验证效果:
重启浏览器,在url地址中输入:
test://456
至此实验完成!