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

      

  • 相关阅读:
    PHP 页面编码声明方法详解(header或meta)
    淘客部分功能实现源码
    CSS3动画效果应用
    JavaScript之Tab标签(原始版)
    JavaScript之淡入淡出
    关于响应式布局
    深入理解 SVG 系列(一) —— SVG 基础
    面试题
    随记
    一道经典面试题-----setTimeout(function(){},0)
  • 原文地址:https://www.cnblogs.com/feiyucha/p/10327558.html
Copyright © 2011-2022 走看看