/*自定义导航栏*/

【ASP】注册表的读写

关于注册表的作用,这里暂不作介绍。主要讨论下注册表的读写方法:

1,首先我们认识下注册表如何让打开:程序=》搜索=》regedit=》

2注册表包含五大类分别是:

1,HKEY_CLASSES_ROOT
2,HKEY_CURRENT_USER
3,HKEY_LOCAL_MACHING
4,HKEY_USERS
5,HKEY_CURRENT_CONFIG

3注册表的写方法:

 //写入注册表
        private void button1_Click(object sender, EventArgs e)
        {
            RegistryKey rk = null;
            if (Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft").SubKeyCount <= 0)
            {
                Registry.LocalMachine.DeleteSubKey("SOFTWARE\\Microsoft");
                Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft");
            }
            rk=Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft",true );
            rk.SetValue("123","练习写入注册表");
            MessageBox.Show("写入成功");
            rk.Close();
        }

4注册表的读方法:

 //读取注册表
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                RegistryKey rk = null;
                rk = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft", true);
                if (rk.GetValue("123") != null)
                {
                    richTextBox1.Text = rk.GetValue("123").ToString();
                }
                else
                {
                    MessageBox.Show("没有关键值");
                }
            }
            catch
            { }
        }

posted @ 2012-11-14 09:34  伏草惟存  阅读(718)  评论(0编辑  收藏  举报