private void DeleteSubKeyTreeInternal(string subkey)
        {
            int errorCode = 0;
            SafeTransactionHandle transactionHandle = this.GetTransactionHandle();
            TransactedRegistryKey key = this.InternalOpenSubKey(subkey, true);

            if (key == null)
            {
                throw new ArgumentException(RegistryProviderStrings.Arg_RegSubKeyAbsent);
            }
            try
            {
                if (key.InternalSubKeyCount() > 0)
                {
                    string[] subKeyNames = key.InternalGetSubKeyNames();
                    for (int i = 0; i < subKeyNames.Length; i++)
                    {
                        key.DeleteSubKeyTreeInternal(subKeyNames[i]);
                    }
                }
            }
            finally
            {
                key.Close();
            }
            errorCode = Microsoft.PowerShell.Commands.Internal.Win32Native.RegDeleteKeyTransacted(this.hkey, subkey, 0, 0, transactionHandle, IntPtr.Zero);
            if (errorCode != 0)
            {
                this.Win32Error(errorCode, null);
            }
        }
        public void DeleteSubKeyTree(string subkey)
        {
            ValidateKeyName(subkey);
            if ((string.IsNullOrEmpty(subkey) || (subkey.Length == 0)) && this.IsSystemKey())
            {
                throw new ArgumentException(RegistryProviderStrings.ArgRegKeyDelHive);
            }
            this.EnsureWriteable();
            int errorCode = 0;
            SafeTransactionHandle transactionHandle = this.GetTransactionHandle();

            subkey = FixupName(subkey);
            this.CheckSubTreeWritePermission(subkey);
            TransactedRegistryKey key = this.InternalOpenSubKey(subkey, true);

            if (key == null)
            {
                throw new ArgumentException(RegistryProviderStrings.Arg_RegSubKeyAbsent);
            }
            try
            {
                if (key.InternalSubKeyCount() > 0)
                {
                    string[] subKeyNames = key.InternalGetSubKeyNames();
                    for (int i = 0; i < subKeyNames.Length; i++)
                    {
                        key.DeleteSubKeyTreeInternal(subKeyNames[i]);
                    }
                }
            }
            finally
            {
                key.Close();
            }
            errorCode = Microsoft.PowerShell.Commands.Internal.Win32Native.RegDeleteKeyTransacted(this.hkey, subkey, 0, 0, transactionHandle, IntPtr.Zero);
            if (errorCode != 0)
            {
                this.Win32Error(errorCode, null);
            }
        }