/// <summary> /// An internal version which does no security checks or argument checking. Skipping the /// security checks should give us a slight perf gain on large trees. /// </summary> private void DeleteSubKeyTreeInternal(string subkey) { RegistryKey key = InternalOpenSubKeyWithoutSecurityChecks(subkey, true); if (key != null) { using (key) { if (key.SubKeyCount > 0) { string[] keys = key.GetSubKeyNames(); for (int i = 0; i < keys.Length; i++) { key.DeleteSubKeyTreeInternal(keys[i]); } } } DeleteSubKeyTreeCore(subkey); } else { throw new ArgumentException(SR.Arg_RegSubKeyAbsent); } }
/// <summary> /// An internal version which does no security checks or argument checking. Skipping the /// security checks should give us a slight perf gain on large trees. /// </summary> private void DeleteSubKeyTreeInternal(string subkey) { RegistryKey key = InternalOpenSubKey(subkey, true); if (key != null) { using (key) { if (key.InternalSubKeyCount() > 0) { string[] keys = key.InternalGetSubKeyNames(); for (int i = 0; i < keys.Length; i++) { key.DeleteSubKeyTreeInternal(keys[i]); } } } DeleteSubKeyTreeCore(subkey); } else { ThrowHelper.ThrowArgumentException(SR.Arg_RegSubKeyAbsent); } }
public void DeleteSubKeyTree(string subkey, bool throwOnMissingSubKey) { ValidateKeyName(subkey); // Security concern: Deleting a hive's "" subkey would delete all // of that hive's contents. Don't allow "". if (subkey.Length == 0 && IsSystemKey()) { ThrowHelper.ThrowArgumentException(SR.Arg_RegKeyDelHive); } EnsureWriteable(); subkey = FixupName(subkey); // Fixup multiple slashes to a single slash CheckPermission(RegistryInternalCheck.CheckSubTreeWritePermission, subkey, false, RegistryKeyPermissionCheck.Default); RegistryKey key = InternalOpenSubKeyWithoutSecurityChecks(subkey, true); if (key != null) { using (key) { if (key.InternalSubKeyCount() > 0) { string[] keys = key.InternalGetSubKeyNames(); for (int i = 0; i < keys.Length; i++) { key.DeleteSubKeyTreeInternal(keys[i]); } } } DeleteSubKeyTreeCore(subkey); } else if (throwOnMissingSubKey) { ThrowHelper.ThrowArgumentException(SR.Arg_RegSubKeyAbsent); } }