語言

RegistryKey.DeleteValue 方法

定義

從此鍵中刪除指定值,若找不到該值則拋出例外。

多載

名稱 Description
DeleteValue(String)

從此鍵中刪除指定的值。

DeleteValue(String, Boolean)

從此鍵中刪除指定的值,並指定若找不到該值是否會觸發例外。

DeleteValue(String)

來源:
RegistryKey.cs

從此鍵中刪除指定的值。

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

參數

name
String

要刪除的值名稱。

例外狀況

name 不是對某個值的有效參考。

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

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

控的 RegistryKey 存在是唯讀的。

範例

此程式碼範例是本類別更大範例 RegistryKey 的一部分。

// Delete the ID value.
testSettings = test9999->OpenSubKey( "TestSettings", true );
testSettings->DeleteValue( "id" );

// Verify the deletion.
Console::WriteLine( dynamic_cast<String^>(testSettings->GetValue(  "id", "ID not found." )) );
testSettings->Close();
using(RegistryKey
    testSettings = test9999.OpenSubKey("TestSettings", true))
{
    // Delete the ID value.
    testSettings.DeleteValue("id");

    // Verify the deletion.
    Console.WriteLine((string)testSettings.GetValue(
        "id", "ID not found."));
}
' Delete the ID value.
testSettings = test9999.OpenSubKey("TestSettings", True)
testSettings.DeleteValue("id")

' Verify the deletion.
Console.WriteLine(CType(testSettings.GetValue( _
    "id", "ID not found."), String))
testSettings.Close()

另請參閱

適用於

DeleteValue(String, Boolean)

來源:
RegistryKey.cs

從此鍵中刪除指定的值,並指定若找不到該值是否會觸發例外。

public:
 void DeleteValue(System::String ^ name, bool throwOnMissingValue);
public void DeleteValue(string name, bool throwOnMissingValue);
member this.DeleteValue : string * bool -> unit
Public Sub DeleteValue (name As String, throwOnMissingValue As Boolean)

參數

name
String

要刪除的值名稱。

throwOnMissingValue
Boolean

表示若找不到指定值,是否應提出例外。 若此參數為 true 且指定值不存在,則會提出例外。 若該參數為且 false 指定值不存在,則不執行任何動作。

例外狀況

name 不是對某值的有效參考,且 throwOnMissingValue 為 true。

-或-

name 是 null。

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

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

控的 RegistryKey 存在是唯讀的。

備註

若 throwOnMissingValue , false則無法判斷刪除是否成功,除非接著嘗試存取剛刪除的值。 因此,刪除登錄檔數值時請特別小心。

另請參閱

適用於