zoukankan      html  css  js  c++  java
  • url protocol

    首先注册服务

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

     Windows Registry Editor Version 5.00  
    [HKEY_CLASSES_ROOTEasyPrint]  
    "URL Protocol"="C:\Program Files\EasyPrint\EasyPrint.exe"  
    @="EasyPrintProtocol"  
    [HKEY_CLASSES_ROOTEasyPrintDefaultIcon]  
    @="C:\Program Files\EasyPrint\EasyPrint.exe,1"  
    [HKEY_CLASSES_ROOTEasyPrintshell]  
    [HKEY_CLASSES_ROOTEasyPrintshellopen]  
    [HKEY_CLASSES_ROOTEasyPrintshellopencommand]  
    @=""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

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

  • 相关阅读:
    vue-router的钩子函数
    vue中父组件和子组件的生命周期钩子
    图片的按需加载代码实现
    关于DNS优化的策略
    在url中输入地址到页面呈现发生了什么
    vue-router的组件传值
    微信小程序wx_request封装
    vue生命周期
    vue生命周期的讨论&容易忽略的知识
    【Vue】---{__ob__: Observer}
  • 原文地址:https://www.cnblogs.com/ives/p/10918409.html
Copyright © 2011-2022 走看看