RegistryKey.DeleteValue Method

Definition

Deletes the specified value from this key, and throws an exception if the value is not found.

Overloads

DeleteValue(String)

Deletes the specified value from this key.

DeleteValue(String, Boolean)

Deletes the specified value from this key, and specifies whether an exception is raised if the value is not found.

DeleteValue(String)

Deletes the specified value from this key.

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

Parameters

name
String

The name of the value to delete.

Exceptions

name is not a valid reference to a value.

The user does not have the permissions required to delete the value.

The RegistryKey being manipulated is closed (closed keys cannot be accessed).

The RegistryKey being manipulated is read-only.

Examples

This code example is part of a larger example provided for the RegistryKey class.

// 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()

See also

Applies to

DeleteValue(String, Boolean)

Deletes the specified value from this key, and specifies whether an exception is raised if the value is not found.

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)

Parameters

name
String

The name of the value to delete.

throwOnMissingValue
Boolean

Indicates whether an exception should be raised if the specified value cannot be found. If this argument is true and the specified value does not exist, an exception is raised. If this argument is false and the specified value does not exist, no action is taken.

Exceptions

name is not a valid reference to a value and throwOnMissingValue is true.

-or-

name is null.

The user does not have the permissions required to delete the value.

The RegistryKey being manipulated is closed (closed keys cannot be accessed).

The RegistryKey being manipulated is read-only.

Remarks

If throwOnMissingValue is false, there is no way to tell if the deletion was successful, without subsequently trying to access the value just deleted. Therefore, use caution when deleting values from the registry in this manner.

See also

Applies to