RegistryKey.DeleteSubKeyTree RegistryKey.DeleteSubKeyTree RegistryKey.DeleteSubKeyTree RegistryKey.DeleteSubKeyTree Method

Definition

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

Overloads

DeleteSubKeyTree(String, Boolean) DeleteSubKeyTree(String, Boolean) DeleteSubKeyTree(String, Boolean) 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) DeleteSubKeyTree(String) DeleteSubKeyTree(String) DeleteSubKeyTree(String)

Deletes a subkey and any child subkeys recursively.

DeleteSubKeyTree(String, Boolean) DeleteSubKeyTree(String, Boolean) DeleteSubKeyTree(String, Boolean) 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.

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

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

throwOnMissingSubKey
Boolean Boolean Boolean 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.

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.

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

Security

RegistryPermission
for the ability to modify the specified registry key. Associated enumeration: Write

SecurityPermission
for the ability to access the specified registry key if it is a remote key. Associated enumeration: UnmanagedCode

DeleteSubKeyTree(String) DeleteSubKeyTree(String) DeleteSubKeyTree(String) DeleteSubKeyTree(String)

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 String String String

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

Exceptions

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).

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.

Security

RegistryPermission
for the ability to modify the specified registry key. Associated enumeration: Write

SecurityPermission
for the ability to access the specified registry key if it is a remote key. Associated enumeration: UnmanagedCode

See Also

Applies to