1.效果
2.代码修改注册表
public static void open_url_startup(string nodeName="mumu.myApp",string exeName= "my-app-path")
{
try
{
string basepath = AppDomain.CurrentDomain.BaseDirectory;
string programFullPath = string.Format("{0}{1}", basepath, exeName);
RegistryKey rkey = Registry.ClassesRoot;
//string a = (string)key.GetValue(nodeName, true);
if (!rkey.Name.Contains(nodeName))
{
RegistryKey software = rkey.CreateSubKey(nodeName);
software.SetValue("URL Protocol", programFullPath);
software.SetValue("", $"mumu.Protocol");
RegistryKey softwareDefaultIcon = software.CreateSubKey("DefaultIcon");
softwareDefaultIcon.SetValue("", string.Format("{0}.exe,L", programFullPath));
RegistryKey softwareShell = software.CreateSubKey("shell");
softwareShell = softwareShell.CreateSubKey("open");
softwareShell = softwareShell.CreateSubKey("command");
softwareShell.SetValue("", string.Format("\"{0}.exe\" \"%L\"", programFullPath));
}
}
catch (Exception ex)
{
Console.Write(ex.Message);
}
}
3.注册表的效果
4.html里访问那个刚刚写入节点的名称mumu.myApp
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<a href="mumu.myApp:这里是你的参数">MyApp</a>
</body>
</html>
exe里要在main里接收参数
注意
-
exe接收的参数要用web的url解码方法才能解析出正确的数据,否则会乱码
-
节点名称不能有下划线,可以有点,不能包含字符和中文