Bewerken

Share via


RegistryKey.DeleteSubKeyTree Method

Definition

Deletes a subkey and any child subkeys recursively, with optional exception handling.

Overloads

DeleteSubKeyTree(String, Boolean)

Deletes the specified subkey and any child subkeys recursively, and specifies whether an exception is raised if the subkey is not found.

DeleteSubKeyTree(String)

Deletes a subkey and any child subkeys recursively.

DeleteSubKeyTree(String, Boolean)

Source:
RegistryKey.cs

Deletes the specified subkey and any child subkeys recursively, and specifies whether an exception is raised if the subkey is not found.

public:
 void DeleteSubKeyTree(System::String ^ subkey, bool throwOnMissingSubKey);
public void DeleteSubKeyTree (string subkey, bool throwOnMissingSubKey);
[System.Runtime.InteropServices.ComVisible(false)]
public void DeleteSubKeyTree (string subkey, bool throwOnMissingSubKey);
member this.DeleteSubKeyTree : string * bool -> unit
[<System.Runtime.InteropServices.ComVisible(false)>]
member this.DeleteSubKeyTree : string * bool -> unit
Public Sub DeleteSubKeyTree (subkey As String, throwOnMissingSubKey As Boolean)

Parameters

subkey
String

The name of the subkey to delete. This string is not case-sensitive.

throwOnMissingSubKey
Boolean

Indicates whether an exception should be raised if the specified subkey cannot be found. If this argument is true and the specified subkey does not exist, an exception is raised. If this argument is false and the specified subkey does not exist, no action is taken.

Attributes

Exceptions

An attempt was made to delete the root hive of the tree.

-or-

subkey does not specify a valid registry subkey, and throwOnMissingSubKey is true.

subkey is null.

The RegistryKey is closed (closed keys cannot be accessed).

The user does not have the necessary registry rights.

The user does not have the permissions required to delete the key.

Applies to

DeleteSubKeyTree(String)

Source:
RegistryKey.cs

Deletes a subkey and any child subkeys recursively.

public:
 void DeleteSubKeyTree(System::String ^ subkey);
public void DeleteSubKeyTree (string subkey);
member this.DeleteSubKeyTree : string -> unit
Public Sub DeleteSubKeyTree (subkey As String)

Parameters

subkey
String

The subkey to delete. This string is not case-sensitive.

Exceptions

subkey is null.

Deletion of a root hive is attempted.

-or-

subkey does not specify a valid registry subkey.

An I/O error has occurred.

The user does not have the permissions required to delete the key.

The RegistryKey being manipulated is closed (closed keys cannot be accessed).

The user does not have the necessary registry rights.

Examples

This code example is part of a larger example provided for the RegistryKey class.

// Delete or close the new subkey.
Console::Write( "\nDelete newly created registry key? (Y/N) " );
if ( Char::ToUpper( Convert::ToChar( Console::Read() ) ) == 'Y' )
{
   Registry::CurrentUser->DeleteSubKeyTree( "Test9999" );
   Console::WriteLine( "\nRegistry key {0} deleted.", test9999->Name );
}
else
{
   Console::WriteLine( "\nRegistry key {0} closed.", test9999->ToString() );
   test9999->Close();
}
// Delete or close the new subkey.
Console.Write("\nDelete newly created registry key? (Y/N) ");
if(Char.ToUpper(Convert.ToChar(Console.Read())) == 'Y')
{
    Registry.CurrentUser.DeleteSubKeyTree("Test9999");
    Console.WriteLine("\nRegistry key {0} deleted.",
        test9999.Name);
}
else
{
    Console.WriteLine("\nRegistry key {0} closed.",
        test9999.ToString());
    test9999.Close();
}
' Delete or close the new subkey.
Console.Write(vbCrLf & "Delete newly created " & _
    "registry key? (Y/N) ")
If Char.ToUpper(Convert.ToChar(Console.Read())) = "Y"C Then
    Registry.CurrentUser.DeleteSubKeyTree("Test9999")
    Console.WriteLine(vbCrLf & "Registry key {0} deleted.", _
        test9999.Name)
Else
    Console.WriteLine(vbCrLf & "Registry key {0} closed.", _
        test9999.ToString())
    test9999.Close()
End If

Remarks

You must have appropriate permissions to delete the subkey and its tree.

Caution

Deleting a particular key will remove all entries below the key in the tree. No warning will be provided. If you want to delete a subkey only when it has no child subkeys, use the DeleteSubKey method.

See also

Applies to