首页 > 其他 > 详细

建立数据文件与程序的关联

时间:2019-01-27 20:15:11      阅读:180      评论:0      收藏:0      [点我收藏+]

实现效果:

  技术分享图片

知识运用:

  public void DeleteSubKey(string subkey)    //删除指定的子项

实现代码:

        public void RefreshSystem()
        {
            Process[] ps = Process.GetProcessesByName("explorer");
            foreach (Process p in ps)
            {
                p.Kill();  
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string notePath = "C:\\Windows\\System32\\notepad.exe";
                string extFile = ".ffy";
                string myContent = "text/plain";
                RegistryKey rk = Registry.ClassesRoot;
                rk = rk.CreateSubKey(extFile);
                rk.SetValue("","自定义的拓展名");
                rk.SetValue("Content Type",myContent);
                rk=rk.CreateSubKey("shell\\open\\Command");
                rk.SetValue("",notePath+" %1");
                rk.Close();
                if (MessageBox.Show("关联成功!") == DialogResult.OK)
                {
                    RefreshSystem(); //刷新explorer进程
                }
            }
            catch (Exception ex)
            { MessageBox.Show(ex.Message); }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string extFile = ".ffy";
            RegistryKey rk = Registry.ClassesRoot;
            rk.CreateSubKey(extFile + "\\shell\\open\\Command");
            rk.DeleteSubKey(extFile+"\\shell\\open\\Command");
            if (MessageBox.Show("关联已取消!") == DialogResult.OK)
            {
                RefreshSystem(); //刷新explorer进程
            }
        }

  

建立数据文件与程序的关联

原文:https://www.cnblogs.com/feiyucha/p/10327558.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!