How to: Delete a Registry Key in Visual Basic
To delete a registry key
DeleteSubKeymethod 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.
DeleteSubKey method returns an empty string if the key/value pair does not exist.
The following conditions may cause an exception:
The name of the key is
The user does not have permissions to delete registry keys (SecurityException).
The key name exceeds the 255-character limit (ArgumentException).
The registry key is read-only (UnauthorizedAccessException).
.NET Framework 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.