Title says it all.. it is very hit and miss.. noticed if I run it outside the IDE it works semi ok.. sometimes the button doesn't execute the push.. but never works outside the ide. Noticed that if I put a statement like debug.print inbetween certain portions it actually works better in "IDE".. my guess is it is executing too fast and doesn't have time to actually process.. but I thought I'd get some input.
Code:
Public Sub WindowModify(Optional ByVal lngTimeout As Currency = 60) 'seconds
On Error GoTo ProcError
Const MAX_LEN As Byte = 255
Dim lngReturn As Long
Dim lngSystemHwnd As Long
Dim lngObtnHwnd As Long
Dim lngCbtnHwnd As Long
Dim lngUserHwnd As Long
Dim lngPassHwnd As Long
Dim strBuff As String
Dim intLen As Integer
Dim intTextArray As Integer
Dim intBtnArray As Integer
Dim lngTextBoxHwnd(0 To 1) As Long
Dim lngButtonHwnd(0 To 1) As Long
intTextArray = 0
intBtnArray = 0
If IsProcessRunning(cnstSystemTray) <> True Then
lngReturn = ExecuteCommand(strSystemTray, , , , False, Left(strSystemTray, InStrRev(strSystemTray, "\")))
If lngReturn <> 0 Then
GoTo ProcError
Else
Do Until lngSystemHwnd <> 0
DoEvents
lngSystemHwnd = FindWindow(vbNullString, "System Enrollment")
frmAutomate.lblStatusMessage.Caption = "Waiting for System Enrollment Window.."
Loop
lblStatusMessage.Caption = "Found System Enrollment Window.."
lngSystemHwnd = GetWindow(lngSystemHwnd, GW_CHILD)
Do Until lngSystemHwnd = 0
lngSystemHwnd = GetWindow(lngSystemHwnd, GW_HWNDNEXT)
strBuff = String(MAX_LEN, vbNullChar)
intLen = GetClassName(lngSystemHwnd, strBuff, MAX_LEN)
If Left(strBuff, intLen) = "Edit" Then
lngTextBoxHwnd(intTextArray) = lngSystemHwnd
intTextArray = intTextArray + 1
ElseIf Left(strBuff, intLen) = "Button" Then
Debug.Print "Found Button: " & lngSystemHwnd
lngButtonHwnd(intBtnArray) = lngSystemHwnd
intBtnArray = intBtnArray + 1
End If
Loop
lblStatusMessage.Caption = "Setting Credentials for System..."
SendMessage lngTextBoxHwnd(0), WM_SETTEXT, 0, ByVal strUsername
SendMessage lngTextBoxHwnd(1), WM_SETTEXT, 0, ByVal strPassword
SendMessage lngButtonHwnd(0), ByVal BM_CLICK, 0&, ByVal 0&
End If
End If
GoTo ProcClean
ProcError:
If lngReturn <> 1 Then
Debug.Print "An error occured in m_WindowModify.WindowModify()"
Debug.Print lngReturn & ": " & GetSystemErrorMessageText(lngReturn)
End If
GoTo ProcClean
ProcClean:
Debug.Print "Exiting Function m_WindowModify.WindowModify()"
End Sub