Share via


How to: Delete a Registry Key in Visual Basic

The DeleteSubKey(String) and DeleteSubKey(String, Boolean) methods can be used to delete registry keys.

Procedure

To delete a registry key

  • Use the DeleteSubKey method to delete a registry key. This example deletes the key Software/TestApp in the CurrentUser hive. You can change this in the code to the appropriate string, or have it rely on user-supplied information.

    My.Computer.Registry.CurrentUser.DeleteSubKey(
        "Software\TestApp")
    

Robust Programming

The DeleteSubKey method returns an empty string if the key/value pair does not exist.

The following conditions may cause an exception:

Security

Registry calls fail if either sufficient run-time permissions are not granted (RegistryPermission) or if the user does not have the correct access (as determined by the ACLs) for creating or writing to settings. For example, a local application that has the code access security permission might not have operating system permission.

See Also

Reference

DeleteSubKey

DeleteSubKey

RegistryKey

Concepts

Security and the Registry (Visual Basic)

Other Resources

Reading from and Writing to the Registry (Visual Basic)