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

具體參數傳遞方式根據需要自行處理即可,系統會將完整請求自動轉發給注冊的程序

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM