zoukankan      html  css  js  c++  java
  • 建立数据文件与程序的关联

    实现效果:

      

    知识运用:

      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进程
                }
            }
    

      

  • 相关阅读:
    四则运算 calc()
    如何创建width与height比例固定的元素
    eslint规则 中文备注
    使用gulp构建工具
    JavaScript 给表格排序
    【转】grunt动态生成文件名
    vim正则表达式(转)
    正则表达式30分钟入门教程(转)
    hdu 1874 Dijkstra算法
    centos7.4安装mysql
  • 原文地址:https://www.cnblogs.com/feiyucha/p/10327558.html
Copyright © 2011-2022 走看看