public static RegKey Parse(string keyPath, bool writable) { string[] tokens = keyPath.Split(new char[] { '\\' }, 2); Microsoft.Win32.RegistryKey rootKey = RegUtility.ParseRootKey(tokens[0]); if (tokens.Length == 1) { return(new RegKey(rootKey)); } string path = tokens[1]; string name = keyPath.Substring(keyPath.LastIndexOf('\\') + 1); try { var key = rootKey.OpenSubKey(path, writable); if (key == null) { return(null); } return(new RegKey(name, key)); } catch { return(null); } }
private void btnFind_Click(object sender, EventArgs e) { if (btnFind.Text == "F&ind") { RegistryKey[] keys; if (cmbSearch.Text == "All Hives") { keys = new RegistryKey[cmbSearch.Items.Count]; for (int i = 0; i < cmbSearch.Items.Count; i++) { keys[i] = RegUtility.ParseRootKey(cmbSearch.Items[i].ToString()); } } else { keys = new RegistryKey[] { RegUtility.ParseRootKey(cmbSearch.Text) } }; if (txtBranch.Text != String.Empty) { keys[0] = keys[0].OpenSubKey(txtBranch.Text); if (keys[0] == null) { UIUtility.DisplayError(this, Properties.Resources.Error_InvalidKey, txtBranch); return; } } RegSearchArgs searchArgs = GetSearchArgs(keys); StartSearch(); try { searcher.Start(searchArgs); } catch (ArgumentException ex) { toolStripStatusLabel1.Text = "Ready."; UIUtility.DisplayError(this, ex.Message, txtPattern); EnableSearch(); return; } searchStarted = true; } else { btnFind.Enabled = false; searcher.Stop(); } }