关于自定义URL协议的方法 DOwn一个(2)

 /// <summary>
        /// 注册表注册
        /// </summary>
        public static bool  SetRegistry( out string error)
        {
            error = "";
            string ProtocolName = string.Empty;
            string ApploctionName = string.Empty;
           
            XmlDocument XmlDoc = new XmlDocument();
            //不能使用Directory.GetCurrentDirectory() 因为在游览器访问的时候Directory.GetCurrentDirectory()的地址是游览器的地址
            string path = Path.Combine(AppLicationPath + @"/", "Config//YGApp.AppPrivateConfig.xml");
            try
            {
                XmlDoc.Load(path);
                XmlNodeList ProtocolNameList = XmlDoc.SelectNodes("//ProtocolName");
                XmlNodeList AppNameList = XmlDoc.SelectNodes("//ApplicationName");
                foreach (XmlNode Nodes in ProtocolNameList)
                    ProtocolName = Nodes.InnerText;
                foreach (XmlNode AppNodes in AppNameList)
                    ApploctionName = AppNodes.InnerText;
                RegistryKey pregkey;
                pregkey = Registry.ClassesRoot.OpenSubKey(ProtocolName);//AppMianName
                string GetRegisValue = string.Empty;
                string RegisterPath = Path.Combine(AppLicationPath + @"/", "Config//YGAPP.RegisterTemplate.config");
                if (pregkey != null && pregkey.GetValue("URL Protocol") != null)
                {
                  
                        //判断注册信息的注册路径是否正确
                        GetRegisValue = pregkey.GetValue("URL Protocol").ToString();
                        if (!GetRegisValue.Equals(Path.Combine(AppLicationPath + @"/", ApploctionName)))
                        {
                            //路径不正确删除项重新注册
                            //pregkey.SetValue("URL Protocol", Application.StartupPath + "//" + ApploctionName);
                            Registry.ClassesRoot.DeleteSubKeyTree(ProtocolName);
                            //pregkey = Registry.ClassesRoot.OpenSubKey(ProtocolName).OpenSubKey("DefaultIcon");
                            WriteFileToTempDir(RegisterPath, ProtocolName, ApploctionName, out error);
                        }
                }
                else
                {

                    if (pregkey != null)
                        Registry.ClassesRoot.DeleteSubKeyTree(ProtocolName);

                    WriteFileToTempDir(RegisterPath, ProtocolName, ApploctionName, out error);
                }
            }
            catch (System.Exception ex)
            {
              
            }
            return string.IsNullOrEmpty(error);
        }

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值