/// <summary> /// Deletes under value from the registry. /// </summary> /// <param name="root">The root note that the value is under.</param> /// <param name="name">The path to the value under the root node.</param> private static void DeleteValue(RegistryKey root, string name) { Param.AssertNotNull(root, "root"); Param.AssertValidString(name, "name"); try { PathInfo pathinfo = RegistryUtils.GetPath(root, name); if (pathinfo.Key != null) { pathinfo.Key.DeleteValue(pathinfo.Stub); } } catch (ArgumentException) { } catch (SecurityException) { } catch (IOException) { } catch (UnauthorizedAccessException) { } }
/// <summary> /// Deletes one key from the registry. /// </summary> /// <param name="root">The root node to delete the key under.</param> /// <param name="name">The path to the key to delete under the root node.</param> private static void DeleteKey(RegistryKey root, string name) { Param.AssertNotNull(root, "root"); Param.AssertValidString(name, "name"); try { int index = name.LastIndexOf("\\", StringComparison.Ordinal); if (-1 == index) { root.DeleteSubKeyTree(name); } else { string delete = name.Substring(index + 1, name.Length - index - 1); PathInfo pathinfo = RegistryUtils.GetPath(root, name); if (pathinfo.Key != null) { pathinfo.Key.DeleteSubKeyTree(delete); } } } catch (ArgumentException) { // This happens when the key does not exist. Just ignore it. } catch (SecurityException) { } }
/// <summary> /// Gets one value from the registry. /// </summary> /// <param name="root">The root key to get the value under.</param> /// <param name="name">The path to the value under the root key.</param> /// <returns>Return the object or null if it could not be found or retrieved.</returns> private static object GetValue(RegistryKey root, string name) { Param.AssertNotNull(root, "root"); Param.AssertValidString(name, "name"); try { PathInfo pathinfo = RegistryUtils.GetPath(root, name); if (pathinfo.Key == null) { return(null); } else { return(pathinfo.Key.GetValue(pathinfo.Stub)); } } catch (SecurityException) { } catch (IOException) { } catch (ArgumentException) { } return(null); }