Book Image

Advanced UFT 12 for Test Engineers Cookbook

Book Image

Advanced UFT 12 for Test Engineers Cookbook

Overview of this book

Table of Contents (18 chapters)
Advanced UFT 12 for Test Engineers Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Deleting a key from the Windows® system registry


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.

Getting ready

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.

How to do it...

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_USER\MyCustomKey\MyCustomData\MyValue"

Set oWshShell = CreateObject("Wscript.Shell")
oWshShell.RegDelete sKeyPath

Set oWshShell = Nothing

How it works...

We simply create a WScript...