Lotus Notes FAQ Visit Our Sponsor!

Can you access Win32 registry keys in LotusScript?

This code goes in the declarations section

Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (Byval hKey As Long, Byval lpSubKey As String, phkResult As Long) As Long
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 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, Byval lpData As String, lpcbData As Integer) As Long
Declare Function RegEnumKey Lib "advapi32.dll" Alias "RegEnumKeyA" (Byval hKey As Long, Byval dwIndex As Long, Byval lpname As String, Byval cbName As Long) As Long
Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias "RegEnumKeyExA" (Byval hKey As Long, Byval dwIndex As Long, Byval lpname As String, lpcbName As Long, Byval lpReserved As Long, Byval lpClass As String, lpcbClass As Long, lpftLastWriteTime As FILETIME) As Long

Declare Function RegSetValueEx& Lib "advapi32.dll" Alias "RegSetValueExA" _
(Byval hKey As Long, Byval lpValueName As String, Byval Reserved As Long, Byval _
dwType As Long, Byval lpData As String, Byval cbData As Long)

Declare Function RegCreateKey& Lib "advapi32.dll" Alias "RegCreateKeyA" (Byval _
hKey As Long, Byval lpSubKey As String, phkResult As Long)

Type FILETIME
     dwLowDateTime As Long
     dwHighDateTime As Long
End Type

'-- Constant Definitions for WIN32API
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_PERFORMANCE_DATA = &H80000004

Const SYNCHRONIZE = &H100000
Const STANDARD_RIGHTS_READ = &H20000
Const STANDARD_RIGHTS_WRITE = &H20000
Const STANDARD_RIGHTS_EXECUTE = &H20000
Const STANDARD_RIGHTS_REQUIRED = &HF0000
Const STANDARD_RIGHTS_ALL = &H1F0000
Const KEY_QUERY_VALUE = &H1
Const KEY_SET_VALUE = &H2
Const KEY_CREATE_SUB_KEY = &H4
Const KEY_ENUMERATE_SUB_KEYS = &H8
Const KEY_NOTIFY = &H10
Const KEY_CREATE_LINK = &H20
Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
Const KEY_WRITE = ((STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY) And (Not SYNCHRONIZE))
Const KEY_EXECUTE = (KEY_READ)
Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or KEY_CREATE_LINK) And (Not SYNCHRONIZE))
Const ERROR_SUCCESS = 0&

' Reg Data Types...
Const REG_NONE = 0                       ' No value type
Const REG_SZ = 1                         ' Unicode nul terminated string
Const REG_EXPAND_SZ = 2                  ' Unicode nul terminated string
Const REG_BINARY = 3                     ' Free form binary
Const REG_DWORD = 4                      ' 32-bit number
Const REG_DWORD_LITTLE_ENDIAN = 4        ' 32-bit number (same as REG_DWORD)
Const REG_DWORD_BIG_ENDIAN = 5           ' 32-bit number
Const REG_LINK = 6                       ' Symbolic Link (unicode)
Const REG_MULTI_SZ = 7                   ' Multiple Unicode strings


This sample code sets some registry keys associated with IBM's Global Network dialer:

KeyName$ = "Software\IBM Global Network\Dialer\Calling\From\"+ActiveLocation.LocName
res1& = RegOpenKeyEx(HKEY_CURRENT_USER, KeyName$ , 0, KEY_ALL_ACCESS, keyhandle)
If res1& <>ERROR_SUCCESS Then
  res1& = RegCreateKey( HKEY_CURRENT_USER, Keyname$, KeyHandle )
End If
If res1& = ERROR_SUCCESS Then
  res = setDialerReg( keyHandle, ThisPhone )
End If
Call RegCloseKey(keyhandle)
          
KeyName$ = "Software\IBM Global Network\Dialer\Settings"
res2& = RegOpenKeyEx(HKEY_CURRENT_USER, KeyName$ , 0, KEY_ALL_ACCESS, keyhandle)
res = setDialerReg( keyHandle, ThisPhone )
Call RegCloseKey(keyhandle)
          
If res1& <> ERROR_SUCCESS And res2& <> ERROR_SUCCESS Then
  Msgbox "The Advantis Dialer is not installed correctly - please contact support"
  Exit Sub
Else
  DialerProgram$ = "c:\Program Files\IBM Global Network\IDialer.EXE"
  KeyName$ = "Software\IBM Global Network\Dialer\Install"
  res3& = RegOpenKeyEx(HKEY_CURRENT_USER, KeyName$ , 0, KEY_ALL_ACCESS, keyhandle)
  If res3& = ERROR_SUCCESS Then
    Dim Ret_Type As Long
    Dim lpFileName As String
    Dim lpReturnedString As String*127
    Dim retSize%
    retSize% = 126
    res4& = RegQueryValueEx( keyhandle, "Directory", 0, Ret_Type, lpReturnedString, retSize% )
    If res4& = ERROR_SUCCESS Then
      DialerProgram$ = Left$(lpReturnedString, retSize%-1) +"\IDialer.exe"
    End If
  End If
  Call RegCloseKey(keyhandle)
  Print "Launching the Advantis Dialer " & DialerProgram$
  rc& = Shell( DialerProgram$ , 2) ' run the dialer and bring the focus to the foreground
End If


Applies to Notes Versions: 4 4.5 4.6 5
Last Modified: July 24, 1998