hi
im trying to use the windows API to enter a password into a reflection window that pops up.
My problem is that i can step through the code using F8, and see the password being
entered and the ok button pressed.
However, when i run the code, it stops at the point where the password prompt window pops up
and the cursor is just blinking waiting for input.
What do i need to do to make this work please? i have tried adding the do loop to wait for the pop up
and also tried application.ontime but both dont work.
thanks
The API function declarations are as follows:
Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Declare Function SetForegroundWindow Lib "user32" ( _
ByVal hWnd As Long) As Long
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Function SetActiveWindow Lib "user32.dll" (ByVal hWnd As Long) As Long
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
(ByVal hWnd1 As Long, _
ByVal hWnd2 As Long, _
ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long
and the function to enter the password is:
Function EnterPassword()
Dim hDialog As Long, hTextbox As Long, hButton As Long, hOK As Long
Dim hWnd As Long
Const WM_SETTEXT = &HC
Const BM_CLICK = &HF5
hWnd = FindWindow(vbNullString, "Reflection Secure Shell Client")
AppActivate "Reflection Secure Shell Client"
hTextbox = FindWindowEx(hWnd, 0, "Edit", "")
SendMessage hTextbox, WM_SETTEXT, ByVal 0, ByVal PASSWORD
hOK = FindWindowEx(hWnd, 0, "Button", "OK")
SetActiveWindow hWnd
SendMessage hOK, BM_CLICK, ByVal CLng(0), ByVal CLng(0)
End Function
The VBA code in excel is
Sub ChangeType()
Dim RTCIS_Session As New Reflection4.Session, I As Long
Dim B As String, Item As String
'
B = "0171B"
' Item = "81431583"
On Error GoTo ErrorHandler
SetUpKeys
With RTCIS_Session
.Visible = True
.ProcessDataComm = False
.ConnectionType = CONNECT_TYPE
.ConnectionSettings = "HOST " & CONNECT_HOST
.ConnectionSettings = "USERNAME " & CONNECT_USERNAME
.Connect
'Loop does not solve it!'
Do Until FindWindow(vbNullString, "Reflection Secure Shell Client") > 0
.Wait 2 'wait 2 seconds'
Loop
EnterPassword
'Does not solve it either!'
Application.OnTime Now + TimeValue("00:00:03"), "EnterPassword"
TransmitWait RTCIS_Session, CR
TransmitWait RTCIS_Session, Bslot & CR
OriginalType = .GetText(10, 89, 10, 94)
For I = 1 To 16
TransmitWait RTCIS_Session, CR
Next I
'other code here'
.quit
End With
Exit sub
ErrorHandler:
Session.MsgBox "Error " & Err.Number & " : " & Err.Description, vbExclamation + vbOKOnly
Resume Next
End Sub
For reference, the setupkeys sub is
Sub SetUpKeys()
CR = Chr(rcCR)
LF = Chr(rcLF)
SI = Chr(rcSI)
End Sub
Bookmarks