110,546
社区成员
发帖
与我相关
我的任务
分享
Uri uri = new Uri("csharp://bbs.csdn.net");
所以要根据不同的协议做不同的操作
你只需要取得uri.Scheme,然后判断并操作即可
之所以qq会自动弹出来是因为你在安装的时候它已经帮各大浏览器都注册好了协议而已
在注册表HKEY_CLASSES_ROOT里
如果你只是开发自己的应用程序,不用鸟windows这套
using Microsoft.Win32;
using System;
using System.IO;
using System.Linq;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.Text = Environment.CommandLine.Split(' ').Last();
Load += delegate
{
try
{
RegisterUriScheme("myqq", this.GetType().Assembly.Location);
}
catch (Exception e)
{
MessageBox.Show("需要管理员权限。myqq协议注册错误:" + e.Message);
}
};
}
public static void RegisterUriScheme(string scheme, string applicationPath)
{
string filename = Path.GetFileName(applicationPath);
using (var schemeKey = Registry.ClassesRoot.CreateSubKey(scheme, writable: true))
{
schemeKey.SetValue("", "URL:myqq Protocol");
schemeKey.SetValue("URL Protocol", "");
using (var defaultIconKey = schemeKey.CreateSubKey("DefaultIcon"))
{
defaultIconKey.SetValue("", filename + ",1");
}
using (var shellKey = schemeKey.CreateSubKey("shell"))
using (var openKey = shellKey.CreateSubKey("open"))
using (var commandKey = openKey.CreateSubKey("command"))
{
commandKey.SetValue("", string.Format("\"{0}\" \"%1\"", applicationPath));
}
}
}
}
}
具体的请原理参考:
Registering an Application to a URI Scheme
https://msdn.microsoft.com/zh-cn/library/aa767914(v=vs.85).aspx