IBM Support

Using API function to capture the username, who is logged on to the particular project

Troubleshooting


Problem

This technote provides you with information about how to use API function to capture the username, who is logged on to the particular project within an IBM® Rational® Robot GUI script.

Resolving The Problem

This information is stored in the registry key "UserID" under "HKEY_CURRENT_USER\Software\Rational Software\Rational Test\8\History".

The RegQueryValueEx is the API function, which reads a value from a registry key. It can read many different types of data, including integers, strings, and any other registry data types. When calling the function, the program does not have to know what the data type of the value being read is. Instead, the program receives information telling it what type of data was read. If an error occurred, the function returns a non-zero error code. If successful, the function returns 0.


Parameters:

-hKey
A handle to the registry key to read the value from. This could also be one of the following flags identifying one of the predefined registry base keys. The flags have identical names to the registry base keys they specify.
HKEY_CLASSES_ROOT
HKEY_CURRENT_CONFIG
HKEY_CURRENT_USER
HKEY_DYN_DATA (Windows 95, 98 only)
HKEY_LOCAL_MACHINE
HKEY_PERFORMANCE_DATA (Windows NT, 2000 only)
HKEY_USERS

-lpValueName

The name of the value to read.

-Reserved
Reserved. Set to 0.

-lpType
Receives one of the following flags identifying the data type of the data being read:

-REG_BINARY
A non-text sequence of bytes.

-REG_DWORD
Same as REG_DWORD_LITTLE_ENDIAN.

-REG_DWORD_BIG_ENDIAN
A 32-bit integer stored in big-endian format. This is the opposite of the way Intel-based computers normally store numbers -- the byte order is reversed.

-REG_DWORD_LITTLE_ENDIAN
A 32-bit integer stored in little-endian format. This is the way Intel-based computers store numbers.

-REG_EXPAND_SZ
A null-terminated string which contains unexpanded environment variables.

-REG_LINK
A Unicode symbolic link.

-REG_MULTI_SZ
A series of strings, each separated by a null character and the entire set terminated by a two null characters.

-REG_NONE
No data type.

-REG_RESOURCE_LIST
A list of resources in the resource map.

-REG_SZ
A string terminated by a null character.

-lpData
Variable, array, or some other object that receives the information read from the registry.

-lpcbData
Set this to the length in bytes of whatever was passed as lpData to receive the data read from the registry. This parameter also receives the length in bytes of the data actually read from the registry.

Constant Definitions:

Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_CONFIG = &H80000005
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_DYN_DATA = &H80000006
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_PERFORMANCE_DATA = &H80000004
Const HKEY_USERS = &H80000003
Const REG_BINARY = 3
Const REG_DWORD = 4
Const REG_DWORD_BIG_ENDIAN = 5
Const REG_DWORD_LITTLE_ENDIAN = 4
Const REG_EXPAND_SZ = 2
Const REG_LINK = 6
Const REG_MULTI_SZ = 7
Const REG_NONE = 0
Const REG_RESOURCE_LIST = 8
Const REG_SZ = 1



Disclaimer

All source code and/or binaries attached to this document are referred to here as "the Program". IBM is not providing program services of any kind for the Program. IBM is providing the Program on an "AS IS" basis without warranty of any kind. IBM WILL NOT BE LIABLE FOR ANY ACTUAL, DIRECT, SPECIAL, INCIDENTAL, OR INDIRECT DAMAGES OR FOR ANY ECONOMIC CONSEQUENTIAL DAMAGES (INCLUDING LOST PROFITS OR SAVINGS), EVEN IF IBM, OR ITS RESELLER, HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.


GUI script example:


Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Const HKEY_CURRENT_USER = &H80000001
Const KEY_READ = &H20019
Const REG_SZ = 1

Sub Main


Dim Result As Integer

'Open the registry key "HKEY_CURRENT_USER\Software\Rational Software\Rational Test\8\History"
' and reads the value named "userID" stored in it.


Dim hKey As Long            'receives a handle to the newly created or opened registry key
Dim subkey As String        'name of the subkey to open
Dim stringbuffer As String  'receives data read from the registry
Dim datatype As Long       'receives data type of read value
Dim slength As Long         'receives length of returned data
Dim retval As Long            'return value

'Set the name of the new key and the default security settings
subkey = "Software\Rational Software\Rational Test\8\History"

'Open the registry key
retval = RegOpenKeyEx(HKEY_CURRENT_USER, subkey, 0, KEY_READ, hKey)
If retval <> 0 Then
msgbox "ERROR: Unable to open registry key!"
Exit Sub
End If

'Make room in the buffer to receive the incoming data.
stringbuffer = Space(255)
slength = 255
'Read the "userID" value from the registry key.
retval = RegQueryValueEx(hKey, "userID", 0, datatype, ByVal stringbuffer, slength)
'Only attempt to display the data if it is in fact a string.
If datatype = REG_SZ Then
'Remove empty space from the buffer and display the result.
stringbuffer = Left(stringbuffer, slength - 1)
msgbox "Username:  " & stringbuffer
Else
' Don't bother trying to read any other data types.
msgbox "Data not in string format.  Unable to interpret data."
End If

' Close the registry key.
retval = RegCloseKey(hKey)


End Sub


[{"Product":{"code":"SSSHDX","label":"Rational Robot"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Datastore","Platform":[{"code":"PF033","label":"Windows"}],"Version":"2003.06.00;2003.06.10;2003.06.12;2003.06.13;2003.06.14;2003.06.15;2003.06.16;7.0;7.0.0.1;7.0.0.2;7.0.0.3;7.0.1;7.0.1.1;7.0.1.2;7.0.0.4;7.0.1.3;7.0.2","Edition":"","Line of Business":{"code":"LOB45","label":"Automation"}}]

Historical Number

132796039

Document Information

More support for:
Rational Robot

Software version:
2003.06.00, 2003.06.10, 2003.06.12, 2003.06.13, 2003.06.14, 2003.06.15, 2003.06.16, 7.0, 7.0.0.1, 7.0.0.2, 7.0.0.3, 7.0.1, 7.0.1.1, 7.0.1.2, 7.0.0.4, 7.0.1.3, 7.0.2

Operating system(s):
Windows

Document number:
327345

Modified date:
16 June 2018

UID

swg21129779