SYS_GetRegistryValue Function

Action

Returns the data value of an item in the Windows registry.

Availability

Windows platforms

Syntax

sValue = SYS_GetRegistryValue (iKey, sPath, sItem [, bConvert])
Variable Description
sValue The item’s data value to be retrieved. STRING.
iKey The registry key. INTEGER
sPath The path to the item through the registry hierarchy. STRING.
sItem The name of the data value to retrieve. If an empty string is used, the default value of the registry key is retrieved. STRING.
bConvert Optional. TRUE if you want a registry value of type REG_DWORD or REG_BINARY to be converted to type INTEGER: See Notes below. Default is FALSE. BOOLEAN.

Notes

Sys_GetRegistryValue can be called from Silk Test Classic or Agent C code, which might be useful if you want to access your application’s runtime settings in the registry.

Sys_GetRegistryValue is executed by the Agent process, not the Silk Test Classic process. To affect the host process, use the function with the hHost notation or machine handle operator. For more information about the machine handle operator and hHost, see Machine handle operator.

Use the include file mswconst.inc to be able to reference key values.

With the Classic Agent, Sys_GetRegistryValue returns an incorrect value when a binary value is used. Use the Open Agent with Sys_GetRegistryValue to avoid this issue.

Sys_GetRegistryValue supports these data types:

  • REG_SZ (string)

  • REG_DWORD (4-byte binary value)

  • REG_BINARY (binary value of arbitrary length)

Retrieved REG_BINARY and REG_DWORD values are formatted within a string which includes the data type prefix, as shown in the following examples:
"REG_BINARY: 14 00 00 7e 8f 99 33 22 08 00 07 00 06"
"REG_DWORD: 0x00008f7e"

If you set bConvert to TRUE and if the registry value returned is a REG_DWORD or REG_BINARY type, Sys_GetRegistryValue converts the registry value to an integer. In the case of a REG_DWORD, it returns the actual value. In the case of a REG_BINARY, it returns the integer produced by taking the first four bytes of the value.

Example

The following example returns the current display resolution:

INTEGER iKey = HKEY_CURRENT_CONFIG // defined in msw32.inc
STRING sPath = "Display\Settings"
STRING sItem = "Resolution"
Print (SYS_GetRegistryValue (iKey, sPath, sItem))
//prints 1280.1024