RegistryKey.DeleteSubKey 方法

定义

删除指定子项。

重载

DeleteSubKey(String)

删除指定子项。

DeleteSubKey(String, Boolean)

删除指定的子项,并指定在找不到该子项时是否引发异常。

DeleteSubKey(String)

Source:
RegistryKey.cs

删除指定子项。

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

参数

subkey
String

要删除的子项的名称。 此字符串不区分大小写。

例外

具有 subkey 子子项。

参数 subkey 未指定有效的注册表项。

subkeynull

用户没有删除该项所需的权限。

要操作的 RegistryKey 已关闭(无法访问关闭的项)。

用户没有必需的注册表权限。

示例

以下示例演示如何使用 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

注解

若要删除子子项,请使用 DeleteSubKeyTree

删除注册表项时要小心。

另请参阅

适用于

DeleteSubKey(String, Boolean)

Source:
RegistryKey.cs

删除指定的子项,并指定在找不到该子项时是否引发异常。

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)

参数

subkey
String

要删除的子项的名称。 此字符串不区分大小写。

throwOnMissingSubKey
Boolean

指示在找不到指定子项的情况下是否引发异常。 如果该参数为 true,并且指定的子项不存在,则引发异常。 如果该参数为 false,并且指定的子项不存在,则不执行任何操作。

例外

subkey 有子级子项。

subkey 未指定有效的注册表项,并且 throwOnMissingSubKeytrue

subkeynull

用户没有删除该项所需的权限。

要操作的 RegistryKey 已关闭(无法访问关闭的项)。

用户没有必需的注册表权限。

注解

若要删除子子项,请使用 DeleteSubKeyTree

删除注册表项时要小心。

另请参阅

适用于