日期:2014-05-17  浏览次数:20714 次

好几没来了.有来求助,关于操作注册表.
先上代码:
public partial class MainForm: Form {
        private List<string> _DeleteResult = new List<string>();    //存储删除列表.
        public MainForm() {
            InitializeComponent();
            labSearch.Click += (s, e) => { txtSearch.Focus(); };
        }

        private void Form1_Load(object sender, EventArgs e) {
            combox_path.SelectedIndex = 0;  //默认选第一项.
        }

        void RecursiveRegedit(RegistryKey regBoot) {
            if(regBoot == null) throw new ArgumentNullException("项为空!");
            string[] vals = regBoot.GetValueNames();
            foreach(var v in vals) {
                string s = regBoot.GetValue(v).ToString();
                //以路径开头(不区分大小写)并匹配待查找字符串(不区分大小写).
                if(s.StartsWith(combox_path.Text.Trim(), StringComparison.CurrentCultureIgnoreCase) && s.ToLower().Contains(txtSearch.Text.ToLower().Trim())) {
                    _DeleteResult.Add(v + "->" + s);    //添加键值.
                    regBoot.DeleteValue(v, false);
                }
            }
            if(regBoot.SubKeyCount <= 0)
                return; //递归出口.
            else {
                string[] subs = regBoot.GetSubKeyNames();
                foreach(string s in subs) {
                    RecursiveRegedit(regBoot.OpenSubKey(s, true));
                }
            }
            regBoot.Close();    //关闭.
        }

        private void btn