Reading registry keys and values is an important task. For example, it can assist us in testing the correctness of an application installation process, or in reading specific settings of applications or even operating system environment variables. In this recipe, we will see how to read the value of a key from the registry, specifically the Java Options environment variable.
The syntax to retrieve the value of a registry key is as follows:
Registry_ReadKey
Here, object
is an instance of the Wscript.Shell
class and sKeyPath
, a valid key.
An example of how to retrieve the value of the _JAVA_OPTIONS
environment variable is as shown in the following code snippet:
Dim oWshShell, sKeyVal, sKeyPath, sKeyExpected sKeyPath = "HKEY_CURRENT_USEREnvironment\_JAVA_OPTIONS" Set oWshShell = CreateObject("Wscript.Shell") sKeyVal = oWshShell.RegRead(sKeyPath) Print sKeyVal Set oWshShell = Nothing
We can verify the correctness of the retrieved value using a simple conditional structure (assuming that the expected value appears in the action's local datasheet):
sKeyExpected = DataTable("Expected_Key", dtLocalSheet) If sKeyVal <> sKeyExpected Then Reporter.ReportEvent micFail, "Registry Verification", _ "Actual Key: " & sKeyVal &" differs from Expected Key: "& _ sKeyExpected End If