RegistryKey.DeleteSubKey Método

Definición

Elimina la subclave especificada.Deletes the specified subkey.

Sobrecargas

DeleteSubKey(String)

Elimina la subclave especificada.Deletes the specified subkey.

DeleteSubKey(String, Boolean)

Elimina la subclave especificada e indica si se inicia una excepción cuando no se encuentra la subclave.Deletes the specified subkey, and specifies whether an exception is raised if the subkey is not found.

DeleteSubKey(String)

Elimina la subclave especificada.Deletes the specified subkey.

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

Parámetros

subkey
String

Nombre de la subclave que se va a eliminar.The name of the subkey to delete. Esta cadena no distingue entre mayúsculas y minúsculas.This string is not case-sensitive.

Excepciones

subkey tiene subclaves secundarias.The subkey has child subkeys

El parámetro subkey no especifica una clave del Registro válida.The subkey parameter does not specify a valid registry key

subkey es nullsubkey is null

El usuario no tiene los permisos necesarios para eliminar la clave.The user does not have the permissions required to delete the key.

La RegistryKey que se ha manipulado está cerrada (no se puede tener acceso a las claves cerradas).The RegistryKey being manipulated is closed (closed keys cannot be accessed).

El usuario no tiene los derechos necesarios en el Registro.The user does not have the necessary registry rights.

Ejemplos

En el ejemplo siguiente se muestra cómo usar DeleteSubKey .The following example demonstrates how to use DeleteSubKey.

using namespace System;
using namespace Microsoft::Win32;

public ref class RegKeyDel
{
public:
    static void Main()
    {
        // Create a subkey named Test9999 under HKEY_CURRENT_USER.
        RegistryKey^ test9999 =
            Registry::CurrentUser->CreateSubKey("Test9999");
        // Create two subkeys under HKEY_CURRENT_USER\Test9999. The
        // keys are disposed when execution exits the using statement.
        RegistryKey^ testName = test9999->CreateSubKey("TestName");
        RegistryKey^ testSettings = test9999->CreateSubKey("TestSettings");

        // Create data for the TestSettings subkey.
        testSettings->SetValue("Language", "French");
        testSettings->SetValue("Level", "Intermediate");
        testSettings->SetValue("ID", 123);

        // delete the subkey "TestName"
        test9999->DeleteSubKey("TestName");
        // delete everything under and including "Test9999"
        Registry::CurrentUser->DeleteSubKeyTree("Test9999");
    }
};

int main()
{
    RegKeyDel::Main();
}
using System;
using Microsoft.Win32;

class RegKeyDel
{
    static void Main()
    {
        // Create a subkey named Test9999 under HKEY_CURRENT_USER.
        RegistryKey test9999 =
            Registry.CurrentUser.CreateSubKey("Test9999");
        // Create two subkeys under HKEY_CURRENT_USER\Test9999. The
        // keys are disposed when execution exits the using statement.
        RegistryKey testName = test9999.CreateSubKey("TestName");
        RegistryKey testSettings = test9999.CreateSubKey("TestSettings");

        // Create data for the TestSettings subkey.
        testSettings.SetValue("Language", "French");
        testSettings.SetValue("Level", "Intermediate");
        testSettings.SetValue("ID", 123);

        // delete the subkey "TestName"
        test9999.DeleteSubKey("TestName");
        // delete everything under and including "Test9999"
        Registry.CurrentUser.DeleteSubKeyTree("Test9999");
    }
}
Imports Microsoft.Win32

Public Class RegKeyDel
    Public Shared Sub Main()
        ' Create a subkey named Test9999 under HKEY_CURRENT_USER.
        Dim test9999 As RegistryKey = _
            Registry.CurrentUser.CreateSubKey("Test9999")
        ' Create two subkeys under HKEY_CURRENT_USER\Test9999. The
        ' keys are disposed when execution exits the using statement.
        Dim testName As RegistryKey = test9999.CreateSubKey("TestName")
        Dim testSettings As RegistryKey = test9999.CreateSubKey("TestSettings")

        ' Create data for the TestSettings subkey.
        testSettings.SetValue("Language", "French")
        testSettings.SetValue("Level", "Intermediate")
        testSettings.SetValue("ID", 123)

        ' delete the subkey "TestName"
        test9999.DeleteSubKey("TestName")
        ' delete everything under and including "Test9999"
        Registry.CurrentUser.DeleteSubKeyTree("Test9999")
    End Sub
End Class

Comentarios

Para eliminar las subclaves secundarias, use DeleteSubKeyTree .To delete child subkeys, use DeleteSubKeyTree.

Tenga cuidado al eliminar claves del registro.Use caution when deleting registry keys.

Consulte también

Se aplica a

DeleteSubKey(String, Boolean)

Elimina la subclave especificada e indica si se inicia una excepción cuando no se encuentra la subclave.Deletes the specified subkey, and specifies whether an exception is raised if the subkey is not found.

public:
 void DeleteSubKey(System::String ^ subkey, bool throwOnMissingSubKey);
public void DeleteSubKey (string subkey, bool throwOnMissingSubKey);
member this.DeleteSubKey : string * bool -> unit
Public Sub DeleteSubKey (subkey As String, throwOnMissingSubKey As Boolean)

Parámetros

subkey
String

Nombre de la subclave que se va a eliminar.The name of the subkey to delete. Esta cadena no distingue entre mayúsculas y minúsculas.This string is not case-sensitive.

throwOnMissingSubKey
Boolean

Indica si debería producirse una excepción si no se puede encontrar la subclave especificada.Indicates whether an exception should be raised if the specified subkey cannot be found. Si este argumento es true y la subclave especificada no existe, se genera una excepción.If this argument is true and the specified subkey does not exist, an exception is raised. Si este argumento es false y la subclave especificada no existe, no se lleva a cabo ninguna acción.If this argument is false and the specified subkey does not exist, no action is taken.

Excepciones

subkey tiene subclaves secundarias.subkey has child subkeys.

subkey no especifica una clave del Registro válida y throwOnMissingSubKey es true.subkey does not specify a valid registry key, and throwOnMissingSubKey is true.

subkey es null.subkey is null.

El usuario no tiene los permisos necesarios para eliminar la clave.The user does not have the permissions required to delete the key.

La RegistryKey que se ha manipulado está cerrada (no se puede tener acceso a las claves cerradas).The RegistryKey being manipulated is closed (closed keys cannot be accessed).

El usuario no tiene los derechos necesarios en el Registro.The user does not have the necessary registry rights.

Comentarios

Para eliminar las subclaves secundarias, use DeleteSubKeyTree .To delete child subkeys, use DeleteSubKeyTree.

Tenga cuidado al eliminar claves del registro.Use caution when deleting registry keys.

Consulte también

Se aplica a