語言

RegistryKey.DeleteSubKey 方法

定義

刪除指定的子鍵。

多載

名稱 Description
DeleteSubKey(String)

刪除指定的子鍵。

DeleteSubKey(String, Boolean)

刪除指定的子金鑰,並指定若找不到子金鑰是否會觸發例外。

DeleteSubKey(String)

來源:
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 參數並未指定有效的登錄鍵

subkey 是 null

使用者沒有刪除該金鑰所需的權限。

控的 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)

來源:
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 不指定有效的登錄鍵,且 throwOnMissingSubKey 為 true。

subkey 是 null。

使用者沒有刪除該金鑰所需的權限。

控的 RegistryKey 對象是封閉的(閉鎖金鑰無法被存取)。

使用者沒有必要的登錄權限。

備註

要刪除子子鍵,請使用 DeleteSubKeyTree。

刪除登錄檔金鑰時請特別小心。

另請參閱

適用於