Site hosted by Angelfire.com: Build your free website today!

Lotus Notes 4.x automatic password entry

Read this before continue: here

As you already know, Lotus Notes has a limited support for Automation.
Since it only supports OLE Automation (A pre-COM objects exposition), you cannot log in directly by code (which, in turn, you can do it with version 5.x).
So, what i will explain here is a hack rather than a "really" way to do our task.
As long as i know, there is no way you can pass password parameter to Initialize method. Then, we need to do in API way.
When we initiate a Notes session with OLE, it shows as a little window to enter password for active user.
We can write/get text from windows outside of our program with API calls. With that in mind, we could write our password to Lotus Notes and... click OK button too.
We will need some APIs declaration and a module to our callback function (more on this later).
Start a new exe program, remove form1, add a bas module and paste the following code inside it. After that, change startup config to Sub Main:
(comments inside code)
Option Explicit
' **********************************
' Part of this code was copied from
' www.mvps.org/vbnet
' **********************************

' We need this to get the handle of main password window:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
                (ByVal lpClassName As String, ByVal lpWindowName As String) _
                As Long

' Function to know if window's class is what we need:
Private Declare Function GetClassName Lib "user32" _
    Alias "GetClassNameA" _
   (ByVal hwnd As Long, _
    ByVal lpClassName As String, _
    ByVal nMaxCount As Long) As Long

' Enumerates all child windows from a given "Father" window:
Public Declare Function EnumChildWindows Lib "user32" _
  (ByVal hWndParent As Long, _
   ByVal lpEnumFunc As Long, _
   ByVal lParam As Long) As Long

' Send windows messages to a given one:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
                (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
                lParam As Any) As Long

' To know which text is inside a given window:
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
                (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) _
                 As Long

' Program begins here:
Sub Main()
Dim ret As Long
' Searching window of Lotus Notes Password Dialog box
' Replace caption with your own
ret = FindWindow(vbNullString, "Contraseña")

' if found, continue else terminate (some fails...>(
If ret <> 0 Then
    Call EnumChildWindows(ret, AddressOf EnumChildProc, &H0)
End If
End Sub

' This function is a callback function to obtain child windows handles:
' It MUST be in a module!
Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
'constants to send to OK button
Const BM_SETSTATE = &HF3
Const WM_LBUTTONDOWN = &H201
Const WM_LBUTTONUP = &H202

'const to set password text
Const WM_SETTEXT = &HC

'vars to hold class name and caption/text of
'windows found
Dim sClass As String
Dim sTitle As String
Dim l As Long
   
'We need a buffer here
sClass = Space$(255)
sTitle = Space$(255)

l = GetClassName(hwnd, sClass, 255)
sClass = Left$(sClass, l)
If sClass = "IRIS.password" Then
    '... we got handle to password's window
    SendMessage hwnd, WM_SETTEXT, 0&, ByVal "your_password_here" 'replace with a valid password
End If
   
'reset var value
l = 0

l = GetWindowText(hwnd, sTitle, 255)
sTitle = Left$(sTitle, l)
' Since i have Notes in spanish, you must to change
' text to compare with
If InStr(1, sTitle, "Aceptar", vbTextCompare) Then
    ' click the button...!
    Call SendMessage(hwnd, WM_LBUTTONDOWN, 0, ByVal 0&)
    Call SendMessage(hwnd, WM_LBUTTONUP, 0, ByVal 0&)
    Call SendMessage(hwnd, BM_SETSTATE, 1, ByVal 0&)
End If
'... done.
EnumChildProc = 1
   
End Function
You can add this code to my previous code regarding Lotus Notes OLE Automation.
As i set this example only to show how code works, we need Lotus Notes running and prompting you for a password.
When you can see Notes's Password window waiting for you, just run our program and you will be inside notes Inbox.
Cheers
Hope you have enjoyed that work as i did.
;)


©2001 - Richie Simonetti