/// <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);
}