RegistryKey.DeleteValue RegistryKey.DeleteValue RegistryKey.DeleteValue RegistryKey.DeleteValue Method

Definition

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

Overloads

DeleteValue(String) DeleteValue(String) DeleteValue(String) DeleteValue(String)

Deletes the specified value from this key.

DeleteValue(String, Boolean) DeleteValue(String, Boolean) DeleteValue(String, Boolean) 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) DeleteValue(String) DeleteValue(String) 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 String String 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).

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

Remarks

On Windows 95, Windows 98, Windows 98 Second Edition, and Windows Millennium Edition, specifying an empty string for the name parameter does not delete the default value.

Security

RegistryPermission
for the ability to delete the specified registry key. Associated enumerations: Write

See Also

DeleteValue(String, Boolean) DeleteValue(String, Boolean) DeleteValue(String, Boolean) 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 String String String

The name of the value to delete.

throwOnMissingValue
Boolean Boolean Boolean 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).

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.

On Windows 95, Windows 98, Windows 98 Second Edition, and Windows Millennium Edition, specifying an empty string for the name parameter does not delete the default value.

Security

RegistryPermission
for the ability to delete the specified registry key. Associated enumerations: Write

See Also

Applies to