RegistryKey.DeleteSubKey Método

Definição

Elimina a subchave especificada.

Sobrecargas

Name Description
DeleteSubKey(String)

Elimina a subchave especificada.

DeleteSubKey(String, Boolean)

Elimina a subchave especificada e especifica se uma exceção é levantada caso a subchave não seja encontrada.

DeleteSubKey(String)

Elimina a subchave especificada.

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

O nome da subchave a apagar. Esta cadeia não é sensível a maiúsculas minúsculas.

Exceções

Tem subkey subchaves filhas

O subkey parâmetro não especifica uma chave de registo válida

subkey é null

O utilizador não tem as permissões necessárias para eliminar a chave.

O RegistryKey ser manipulado é fechado (as chaves fechadas não podem ser acedidas).

O utilizador não tem os direitos necessários no registo.

Exemplos

O exemplo a seguir demonstra como usar DeleteSubKeyo .

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

Observações

Para eliminar subchaves filhas, use DeleteSubKeyTree.

Tenha cuidado ao eliminar chaves do registo.

Ver também

Aplica-se a

DeleteSubKey(String, Boolean)

Elimina a subchave especificada e especifica se uma exceção é levantada caso a subchave não seja encontrada.

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

O nome da subchave a apagar. Esta cadeia não é sensível a maiúsculas minúsculas.

throwOnMissingSubKey
Boolean

Indica se deve ser criada uma exceção caso a subchave especificada não seja encontrada. Se este argumento for true e a subchave especificada não existir, é levantada uma exceção. Se este argumento for false e a subchave especificada não existir, não é tomada qualquer ação.

Exceções

subkey tem subchaves de criança.

subkey não especifica uma chave de registo válida, e throwOnMissingSubKey é true.

subkey é null.

O utilizador não tem as permissões necessárias para eliminar a chave.

O RegistryKey ser manipulado é fechado (as chaves fechadas não podem ser acedidas).

O utilizador não tem os direitos necessários no registo.

Observações

Para eliminar subchaves filhas, use DeleteSubKeyTree.

Tenha cuidado ao eliminar chaves do registo.

Ver também

Aplica-se a