Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact


Writing to Logon box


Writing to Logon box

Author
Message
macroman
macroman
Forum God
Forum God (11K reputation)Forum God (11K reputation)Forum God (11K reputation)Forum God (11K reputation)Forum God (11K reputation)Forum God (11K reputation)Forum God (11K reputation)Forum God (11K reputation)Forum God (11K reputation)

Group: Forum Members
Posts: 71, Visits: 264
Hi! I don't have much experience using API calls, but I am trying to write some code to fill in the username, password and click the OK button. I have been able to get the control handles with FindWindowEx and tried using SetWindowText to write the info, but it didn't work right. I have the Analyzer.exe from the APIGuide website and it confirms the name and password were written to the edit boxes, but they are not visible and clicking the OK button doesn't satisfy the requirements - the logon box comes right back up. Is there a better API call or a better method to use? Any suggestions are appreciated. Here's the code I tried:

Private 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
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Dim tWnd As Long, bWnd As Long, cWnd As Long, ncWnd As Long


Private Sub main()
    'Get the logon window handle
    tWnd = FindWindow("#32770", vbNullString)
    'Get the username's window handle
    bWnd = FindWindowEx(tWnd, ByVal 0, "EDIT", vbNullString)
    'paste in username
    myuser = "user" & Chr$(0)
    SetWindowText bWnd, myuser
    'get password window handle
    cWnd = FindWindowEx(tWnd, bWnd, "EDIT", vbNullString)
    'paste in password
    mypass = "password" & Chr$(0)
    SetWindowText cWnd, mypass

    'if this works, need to focus and click the OK button or sendkey "enter"
End Sub


 

Edited
8/27/2005 by macroman
kwandobe
kwandobe
Forum God
Forum God (5.8K reputation)Forum God (5.8K reputation)Forum God (5.8K reputation)Forum God (5.8K reputation)Forum God (5.8K reputation)Forum God (5.8K reputation)Forum God (5.8K reputation)Forum God (5.8K reputation)Forum God (5.8K reputation)

Group: Forum Members
Posts: 22, Visits: 4
I think DOS said it best when he released his BAS file with this in it. This works for AOL chatsends, but I would be guessing that your username and password text boxs would be no different.

Public Sub ChatSend(Chat As String)
   Dim aolframe As Long, mdiclient As Long, aolchild As Long
   Dim richcntl As Long
      aolframe = FindWindow("aol frame25", vbNullString)
      mdiclient = FindWindowEx(aolframe, 0&, "mdiclient", vbNullString)
      aolchild = FindWindowEx(mdiclient, 0&, "aol child", vbNullString)
      richcntl = FindWindowEx(aolchild, 0&, "richcntl", vbNullString)
   Call SendMessageByString(richcntl, WM_SETTEXT, 0&, Chat$)
   Call SendMessageLong(richcntl, WM_CHAR, ENTER_KEY, 0&Wink
End Sub

 

Let me know if you need some more help. I have been programming in vb for 6 years, so I may be of some great assistance.

-kwandobe


Edited
8/31/2005 by kwandobe
macroman
macroman
Forum God
Forum God (11K reputation)Forum God (11K reputation)Forum God (11K reputation)Forum God (11K reputation)Forum God (11K reputation)Forum God (11K reputation)Forum God (11K reputation)Forum God (11K reputation)Forum God (11K reputation)

Group: Forum Members
Posts: 71, Visits: 264
Thanks a bunch! I will try it at my next opportunity. On our system at work I get this network logon box several times a day and always first thing in the morning, so tomorrow morning I will test out the code and let you know if it works or not.

PS does the Wink at the end of the last line of code represent a ; followed by a closing ) ?

Edited
9/1/2005 by macroman
macroman
macroman
Forum God
Forum God (11K reputation)Forum God (11K reputation)Forum God (11K reputation)Forum God (11K reputation)Forum God (11K reputation)Forum God (11K reputation)Forum God (11K reputation)Forum God (11K reputation)Forum God (11K reputation)

Group: Forum Members
Posts: 71, Visits: 264
Need a little more info, like what the variables WM_SETTEXT, Chat$, WM_CHAR and ENTER_KEY would be set to...
kwandobe
kwandobe
Forum God
Forum God (5.8K reputation)Forum God (5.8K reputation)Forum God (5.8K reputation)Forum God (5.8K reputation)Forum God (5.8K reputation)Forum God (5.8K reputation)Forum God (5.8K reputation)Forum God (5.8K reputation)Forum God (5.8K reputation)

Group: Forum Members
Posts: 22, Visits: 4
Public Const WM_SETTEXT = &HC
Public Const WM_CHAR = &H102
Public Const ENTER_KEY = 13

Chat$ stands for the string you wish to pass for the password or username.

The last line of the code that appears &Wink is "& )".

-kwandobe


macroman
macroman
Forum God
Forum God (11K reputation)Forum God (11K reputation)Forum God (11K reputation)Forum God (11K reputation)Forum God (11K reputation)Forum God (11K reputation)Forum God (11K reputation)Forum God (11K reputation)Forum God (11K reputation)

Group: Forum Members
Posts: 71, Visits: 264
Semi-success! I was able to write to the text boxes just fine but couldn't get the OK button to click, and I know from the Analyzer that I was supplying the right handle to the SendMessage command... are you sending the ENTER_KEY to the form or to a button on the form???

Is there a handy listing of the constants used with these commands? I tried to find such a table on the internet, searching Google with WM_SETTEXT. Mostly I got lost in the labyrnth of MSDN... I know somewhere I saw a _BUTTONCLICK constant mentioned, but haven't found my way back to wherever that was! Sooner or later I am going to get a book on this subject.

Edited
9/8/2005 by macroman
GO


Similar Topics


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....

















A1VBCode Forums


Search