url protocol

首先注册服务

方法1,保存为reg文件直接执行,需要按需修改路径

 Windows Registry Editor Version 5.00  
[HKEY_CLASSES_ROOT\EasyPrint]  
"URL Protocol"="C:\\Program Files\\EasyPrint\\EasyPrint.exe"  
@="EasyPrintProtocol"  
[HKEY_CLASSES_ROOT\EasyPrint\DefaultIcon]  
@="C:\\Program Files\\EasyPrint\\EasyPrint.exe,1"  
[HKEY_CLASSES_ROOT\EasyPrint\shell]  
[HKEY_CLASSES_ROOT\EasyPrint\shell\open]  
[HKEY_CLASSES_ROOT\EasyPrint\shell\open\command]  
@="\"C:\\Program Files\\EasyPrint\\EasyPrint.exe\" \"%1\""  

方法2,在程序中自动注册服务,此操作可以放到安装程序中,根据实际情况获取path即可

var path = "E:\\code\\EasyPrint\\EasyPrint\\bin\\Debug";
            List<string> cmds =
            new List<string>{
               "/c" + $"reg add \"HKCR\\EasyPrint\" /f /ve  /d \"EasyPrintProtocol\"",
               "/c" + $"reg add \"HKCR\\EasyPrint\" /f /v \"URL Protocol\"  /d \"",
               "/c" + $"reg add \"HKCR\\EasyPrint\\DefaultIcon\" /f /ve  /d \""+path+"\\EasyPrint.exe,1\"",
               "/c" + $"reg add \"HKCR\\EasyPrint\\shell\\open\\command\" /f /ve  /d \"\\\""+path+"\\EasyPrint.exe\\\"  \\\"%1\\\"\""
            };
            foreach (var command in cmds)
            {
                Process p = new Process
                {
                    StartInfo =
                    {
                        FileName = "cmd.exe",
                        Arguments = command,
                        UseShellExecute = false,
                        RedirectStandardInput = true,
                        RedirectStandardOutput = true,
                        CreateNoWindow = true
                    }
                };
                p.Start();
                p.StandardInput.WriteLine("exit");
                p.Close();
            }

将会在系统中注册一个协议,此协议名称根据注册表的key决定,此处为EasyPrint,大小写无关

调用时即使用  EasyPrint://par1&par2

具体参数传递方式根据需要自行处理即可,系统会将完整请求自动转发给注册的程序

 

转载于:https://www.cnblogs.com/ives/p/10918409.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值