Exemplo n.º 1
0
        /// <summary>
        /// 注册注册表.
        /// http://blog.csdn.net/jiutao_tang/article/details/6563646
        /// </summary>
        private static void REGISTER_REGTABLE()
        {
            //bool action = true;
            if (!FileTypeRegister.FileTypeRegistered(".hoyi")) //如果文件类型没有注册,则进行注册
            {
                FileTypeRegInfo fileTypeRegInfo = new FileTypeRegInfo(".hoyi"); //文件类型信息
                fileTypeRegInfo.Description = "HOYI ER图、类图设计";
                fileTypeRegInfo.ExePath = Application.ExecutablePath;
                fileTypeRegInfo.ExtendName = ".hoyi";
                fileTypeRegInfo.IcoPath = Application.StartupPath + "\\hoyi.ico"; //文件图标使用应用程序的
                FileTypeRegister fileTypeRegister = new FileTypeRegister(); //注册
                FileTypeRegister.RegisterFileType(fileTypeRegInfo);

                Process[] process = Process.GetProcesses(); //重启Explorer进程,使更新立即生效
                var p = (from proc in process
                         where proc.ProcessName.Equals("explorer")
                         select proc).FirstOrDefault();
                p.Kill();
            }
            //else
            //{
            //    FileTypeRegInfo fileTypeRegInfo = new FileTypeRegInfo(".hoyi"); //文件类型信息
            //    fileTypeRegInfo.Description = "HOYI ER图、类图设计";
            //    fileTypeRegInfo.ExePath = Application.ExecutablePath;
            //    fileTypeRegInfo.ExtendName = ".hoyi";
            //    fileTypeRegInfo.IcoPath = Application.StartupPath + "\\hoyi.ico"; //文件图标使用应用程序的
            //    FileTypeRegister.UpdateFileTypeRegInfo(fileTypeRegInfo);

            //    Process[] process = Process.GetProcesses(); //重启Explorer进程,使更新立即生效
            //    var p = (from proc in process
            //             where proc.ProcessName.Equals("explorer")
            //             select proc).FirstOrDefault();
            //    p.Kill();
            //}
        }
Exemplo n.º 2
0
 /// <summary>
 /// GetFileTypeRegInfo 得到指定文件类型关联信息
 /// </summary>        
 public static FileTypeRegInfo GetFileTypeRegInfo(string extendName)
 {
     if (!FileTypeRegistered(extendName))
     {
         return null;
     }
     FileTypeRegInfo regInfo = new FileTypeRegInfo(extendName);
     string relationName = extendName.Substring(1, extendName.Length - 1).ToUpper() + "_FileType";
     RegistryKey relationKey = Registry.ClassesRoot.OpenSubKey(relationName);
     regInfo.Description = relationKey.GetValue("").ToString();
     RegistryKey iconKey = relationKey.OpenSubKey("DefaultIcon");
     regInfo.IcoPath = iconKey.GetValue("").ToString();
     RegistryKey shellKey = relationKey.OpenSubKey("Shell");
     RegistryKey openKey = shellKey.OpenSubKey("Open");
     RegistryKey commandKey = openKey.OpenSubKey("Command");
     string temp = commandKey.GetValue("").ToString();
     regInfo.ExePath = temp.Substring(0, temp.Length - 3);
     return regInfo;
 }
Exemplo n.º 3
0
        /// <summary>
        /// UpdateFileTypeRegInfo 更新指定文件类型关联信息
        /// </summary>    
        public static bool UpdateFileTypeRegInfo(FileTypeRegInfo regInfo)
        {
            if (!FileTypeRegistered(regInfo.ExtendName))
            {
                return false;
            }

            string extendName = regInfo.ExtendName;
            string relationName = extendName.Substring(1, extendName.Length - 1).ToUpper() + "_FileType";
            RegistryKey relationKey = Registry.ClassesRoot.OpenSubKey(relationName, true);
            relationKey.SetValue("", regInfo.Description);
            RegistryKey iconKey = relationKey.OpenSubKey("DefaultIcon", true);
            iconKey.SetValue("", regInfo.IcoPath);
            RegistryKey shellKey = relationKey.OpenSubKey("Shell");
            RegistryKey openKey = shellKey.OpenSubKey("Open");
            RegistryKey commandKey = openKey.OpenSubKey("Command", true);
            commandKey.SetValue("", regInfo.ExePath + " %1");
            relationKey.Close();
            return true;
        }
Exemplo n.º 4
0
 /// <summary>
 /// RegisterFileType 使文件类型与对应的图标及应用程序关联起来。
 /// </summary>        
 public static void RegisterFileType(FileTypeRegInfo regInfo)
 {
     if (FileTypeRegistered(regInfo.ExtendName))
     {
         return;
     }
     string relationName = regInfo.ExtendName.Substring(1, regInfo.ExtendName.Length - 1).ToUpper() + "_FileType";
     RegistryKey fileTypeKey = Registry.ClassesRoot.CreateSubKey(regInfo.ExtendName);
     fileTypeKey.SetValue("", relationName);
     fileTypeKey.Close();
     RegistryKey relationKey = Registry.ClassesRoot.CreateSubKey(relationName);
     relationKey.SetValue("", regInfo.Description);
     RegistryKey iconKey = relationKey.CreateSubKey("DefaultIcon");
     iconKey.SetValue("", regInfo.IcoPath);
     RegistryKey shellKey = relationKey.CreateSubKey("Shell");
     RegistryKey openKey = shellKey.CreateSubKey("Open");
     RegistryKey commandKey = openKey.CreateSubKey("Command");
     commandKey.SetValue("", regInfo.ExePath + " %1");
     relationKey.Close();
 }