Automated tests rarely delete registry keys and values. However, in some cases (such as in the case described in the previous recipe), deleting the custom key would be a reasonable cleaning procedure. In this recipe, we will see how to do it.
From the File menu, navigate to New | Test, or use the Ctrl + N shortcut. You can use the same test as in the previous recipe.
The syntax to delete the value of a registry key is as follows:
object.RegDelete sKeyPath
Here, object
is an instance of the Wscript.Shell
class and sKeyPath
a valid key.
For example, to delete the new custom string (REG_SZ
) type key we created in the previous recipe, use the following code snippet:
Dim oWshShell, sKeyPath, sKeyName, sKeyVal, sKeyType sKeyPath = "HKEY_CURRENT_USERMyCustomKeyMyCustomDataMyValue" Set oWshShell = CreateObject("Wscript.Shell") oWshShell.RegDelete sKeyPath Set oWshShell = Nothing