Domino Code Fragment

Code Name*
Calling Windows Registery APIs to locates Notes executable path
Date*
04/29/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.52.14.85.76
Description*
Calling Windows Registery APIs to retrieve registery values from Lotus Scrip
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:

'// Declarations
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, Byval lpData As String, lpcbData As Long) As Long


Const HKEY_LOCAL_MACHINE = &H80000002&
Const KEY_ALL_ACCESS = &H3F&
Const REG_SZ = 1&


'--------------------------

Public Sub NotesPath( )
'######################################################################
'# SUB: NotesPath
'#
'# AUTHOR: Peter Townsend
'#
'# CREATED: October 14, 1998
'#
'# PURPOSE:
'# Locates Notes executable path from Windows registry.
'#
'# FNCS/SUBS CALLED:
'# None
'#
'######################################################################


On Error Goto ErrorHandler

'----------------------------------------------------------------------------------------------------------------
'| DECLARATIONS
'----------------------------------------------------------------------------------------------------------------
Dim exePath As String
Dim exePathA As String
Dim envPath As String
Dim hKey As Long
Dim sKey As String
Dim vValue As Long
Dim lRetVal As Long


Dim editPath As Integer
Dim pos1 As Integer
Dim pos2 As Integer
Dim charArray() As Integer


'----------------------------------------------------------------------------------------------------------------
'| INITIALIZE
'----------------------------------------------------------------------------------------------------------------
sKey = "Software\\Lotus\\Notes\\4.0"
vValue = 64
exePath = " "


'----------------------------------------------------------------------------------------------------------------
'| GET NOTES EXE PATH FROM REGISTRY
'----------------------------------------------------------------------------------------------------------------
lRetVal = RegOpenKeyEx( &H80000002 , "Software\Lotus\Notes\4.0" , 0 , &H3F , hKey )


lRetVal = RegQueryValueEx(hKey, "Path", 0, 1, exePath, vValue)

'// Because the string exePath is somehow permanently set to 64 characters wide
'// it is necessary to do the following hocus pocus to arrive at a truncated string
'// containing the executable path.
exePath = Ucase(exePath)
pos1 = Instr( exePath , " " )
Redim charArray(1 To pos1-2)
For index = 1 To pos1-2
charArray(index) = Asc(Mid$(exePath , index , 1 ))
Next
exePathA = ""
Forall code In charArray
exePathA = exePathA & Chr( code )
End Forall


'----------------------------------------------------------------------------------------------------------------
'| GET PATH ENVIRONMENT VALUE
'----------------------------------------------------------------------------------------------------------------
envPath = Environ( "PATH" )
envPath = Ucase(envPath)


'----------------------------------------------------------------------------------------------------------------
'| IS NOTES EXE PATH IN PATH ENVIRONMENT VARIABLE?
'----------------------------------------------------------------------------------------------------------------
editPath = False
pos1 = Instr( envPath , exePathA ) '// Is exePath in PATH?
pos2 = Instr( envPath , exePathA & "\" ) '// Is it actually a sub-directory?
If pos1 = 0 Then
editPath = True
Elseif pos1 = pos2 Then
pos1 = Instr( pos1+1 , envPath , exePathA )
If pos1 = 0 Then
editPath = True
End If
End If


'// exePath is not present in environ PATH; edit AUTOEXEC.
If editPath = True Then
'// Add exePath to Autoexec.bat file path
Dim fileNum As Integer


fileNum = Freefile()
Open "C:\AUTOEXEC.BAT" For Append As fileNum
Print #fileNum,
Print #fileNum , "SET PATH=%PATH%;" & Ucase(exePathA)
Close fileNum
Messagebox "Your AUTOEXEC.BAT file has been altered to include the Notes executable path. " & _
"For the changes to take effect, you must shut down Notes and reboot your computer." , MB_OK , _
"REBOOT"


End If

Exit Sub

ErrorHandler:
Messagebox "Error #" & Str(Err) & " - [" & Error & "] occurred in Sub [NotesPath]", _
MB_OK, "ERROR " & Str(Err)


End Sub