public void DeleteFoundRegKeys(RegistryKey regKey, bool includeSubKeys, XmlReader xmlChildren) { if (regKey == null) { return; } var regexSubKeys = new Dictionary <string, bool>(); var regexValueNames = new List <string>(); while (xmlChildren.Read()) { switch (xmlChildren.Name) { case "IfSubKey": { var searchText = xmlChildren.GetAttribute("SearchText"); var recurse = xmlChildren.GetAttribute("Recursive") == "Y"; if (searchText != null) { regexSubKeys.Add(searchText, recurse); } break; } case "IfValueName": { var searchText = xmlChildren.GetAttribute("SearchText"); regexValueNames.Add(searchText); break; } } } var valueNames = RecurseRegKeyValueNames(regKey, regexValueNames, includeSubKeys); var subKeys = RecurseRegKeySubKeys(regKey, regexSubKeys, includeSubKeys); foreach (var kvp in valueNames) { RegistryValueNames.Add(kvp.Key, kvp.Value); } foreach (var kvp in subKeys) { RegistrySubKeys.Add(kvp.Key, kvp.Value); } }
public void DeleteValue(RegistryKey regKey, string searchText) { if (regKey == null) { return; } Wizard.CurrentFile = regKey.Name; string[] regValueNames = null; try { regValueNames = regKey.GetValueNames(); } catch (SecurityException ex) { Debug.WriteLine("The following error occurred: " + ex.Message + "\nUnable to get value names for " + regKey); } catch (UnauthorizedAccessException ex) { Debug.WriteLine("The following error occurred: " + ex.Message + "\nUnable to get value names for " + regKey); } if (regValueNames == null) { return; } // Get value names that match regex var valueNames = regValueNames.Where(valueName => Regex.IsMatch(valueName, searchText)).ToList(); if (!RegistryValueNames.ContainsKey(regKey)) { // Create new entry if regkey doesnt exist RegistryValueNames.Add(regKey, valueNames.ToArray()); } else { // Append value names to existing entry valueNames.AddRange(RegistryValueNames[regKey]); RegistryValueNames[regKey] = valueNames.ToArray(); } }