How to retrieve values from your system's registry
Here's an example of how to retrieve values from your system's registry. The first part is a generic LotusScript function
that retrieves just about any value you request. The last two parts are examples of how to use the function to retrieve
the computer name and Notes path from the registry.
(Declarations)
Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_USERS = &H80000003
Public Const HKEY_CURRENT_CONFIG = &H80000005
Public Const HKEY_DYN_DATA = &H80000006
Public Const REG_SZ = 1 ' Unicode null-terminated string
Public Const REG_BINARY = 3 ' Free form binary
Public Const REG_DWORD = 4 ' 32-bit number
Public Const ERROR_SUCCESS = 0&
Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (Byval hKey As Long, _
Byval lpSubKey As String, phkResult As Long) As Long
Declare Function RegCloseKey Lib "advapi32.dll" (Byval hKey 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
Function GetSettingString(hKey As Long, strPath As String, strValue As String) As String
Dim hCurKey As Long
Dim lResult As Long
Dim lValueType As Long
Dim strBuffer As String
Dim lDataBufferSize As Long
Dim intZeroPos As Integer
Dim lRegResult As Long
GetSettingString = ""
lRegResult = RegOpenKey(hKey, strPath, hCurKey)
lRegResult = RegQueryValueEx(hCurKey, strValue, 0&, lValueType, Byval 0&, lDataBufferSize)
If lRegResult = ERROR_SUCCESS Then
If lValueType = REG_SZ Then
strBuffer = String(lDataBufferSize, " ")
lResult = RegQueryValueEx(hCurKey, strValue, 0&, 0&, Byval strBuffer,
lDataBufferSize)
intZeroPos = Instr(strBuffer, Chr$(0))
If intZeroPos > 0 Then
GetSettingString = Left$(strBuffer, intZeroPos - 1)
Else
GetSettingString = strBuffer
End If
End If
Else
' there is a problem
End If
lRegResult = RegCloseKey(hCurKey)
End Function
This subroutine shows how to retrieve the computer name from the registry.
Sub Initialize
Dim ComputerName As String
ComputerName=GetSettingString( HKEY_LOCAL_MACHINE, _
"System\CurrentControlSet\Control\ComputerName\ComputerName", _
"ComputerName")
Messagebox ComputerName,,"The ComputerName is"
End Sub
This subroutine shows how to retrieve the Notes program directory.
You'll need to indicate your Notes version.
Sub Initialize
Dim NotesProgramPath As String
NotesProgramPath=GetSettingString( HKEY_LOCAL_MACHINE, _
"Software\Lotus\Notes\5.0", _
"Path")
Messagebox NotesProgramPath,,"The Path to Notes Program is"
End Sub
strFullDir = String$(127,0)
strFullDir = Strleft(strFullDir, Chr(0)) & "notes.exe"