Reading the Windows registry with Rational® Functional Tester
The Windows® registry is a database used by the Windows® operating system to store configuration information. Often it becomes necessary for a tester to read information out of this database using Rational® Functional Tester commands. This topic provides some examples for doing this.
The following example is applicable for scripts running on Windows®:
#Region " Script Header "
' Functional Test Script
' author Administrator
Imports Microsoft.VisualBasic
Imports Rational.Test.Ft
Imports Rational.Test.Ft.Object.Interfaces
Imports Rational.Test.Ft.Object.Interfaces.SAP
Imports Rational.Test.Ft.Object.Interfaces.Siebel
Imports Rational.Test.Ft.Script
Imports Rational.Test.Ft.Value
Imports Rational.Test.Ft.Vp
Imports System.Windows.Forms
#End Region
Public Class RegistryExample
Inherits RegistryExampleHelper
'Script Name : RegistryExample
'Generated : Jul 20, 2006 3:15:34 PM
'Description : Functional Test Script
'Original Host : Windows XP x86 5.1 build 2600 Service Pack 2
'since 2006/07/20
'author Administrator
Public Function TestMain(ByVal args() As Object)
SetOption(IOptionName.BRING_UP_LOGVIEWER, False)
Try
' Use this code to extract String (REG_SZ) values
' from the registry.
Dim RegKeyString As String = "HKEY_LOCAL_MACHINE\SOFTWARE\Rational Software\Rational Test\8\Rational FT Install Directory"
Dim RegValueString As String = GetOperatingSystem().GetRegistryValue(RegKeyString)
MessageBox.Show(RegValueString, "String Registry Value")
Catch E As NoSuchRegistryKeyException
MessageBox.Show("Error finding registry key.")
System.Console.WriteLine("No Such Registry Key Exception." + E.toString)
End Try
Try
' Use this code to extract Integer (DWORD) values from the
' registry.
Dim RegKeyInt As String = "HKEY_CURRENT_USER\Control Panel\Desktop\LowLevelHooksTimeout"
Dim RegValueInt As Integer = GetOperatingSystem().GetRegistryIntValue(RegKeyInt)
MessageBox.Show(RegValueInt, "Integer Registry Value")
Catch E As NoSuchRegistryKeyException
MessageBox.Show("Error finding registry key.")
System.Console.WriteLine("No Such Registry Key Exception. (" + E.toString + ")")
End Try
End Function
End Class
There are two commands available to Rational® Functional Tester users to read values
from the registry. The GetRegistryValue
command is used
to read string values from the registry. The GetRegistryIntValue
is
used to read integer values from the registry. The terms "REG_SZ" describe
the string and integer types. Both of the commands take a type String
argument,
which contains the registry key to extract.
The example extracts both a string and an integer value from the registry.
Looking first at the String
value segment, notice the core
code:
Dim RegKeyString As String = "HKEY_LOCAL_MACHINE\SOFTWARE\Rational Software\Rational Test\8\Rational FT Install Directory"
Dim RegValueString As String = GetOperatingSystem().GetRegistryValue(RegKeyString)
MessageBox.Show(RegValueString, "String Registry Value")
The first line creates a type String
variable, which
contains the registry value to extract. The second line executes the command
and stores it in the type String
variable RegValueString
.
The third line uses the MessageBox
class to display the
registry value in a message box on the screen.