|
-
Jun 21st, 2011, 07:39 PM
#1
Thread Starter
New Member
External Form Values?
I used to code a lot "back in the day" with Visual Basic and haven't for some time now. I am trying to develop a program that I believe would use API functionality. There was one program in particular that I remember coding. This program would simulate clicks to buttons on other applications, in order to make these programs act as if there were a user physically typing in or clicking data. An example would be: A AOL instant messenger brute forcer. At the time I could not use the windows sockets to connect to the AIM server and enter account data so I made it to where (with the AIM application open) the program would input data into the username and password field and then "click" the submit button. I cannot remember what the form values were called for helping the program find the input area for username, password, and the submit button.
That is just an example. If you have any idea what I'm talking about please let me know what I'm looking for and what the technical name is for it. Thanks.
-
Jun 26th, 2011, 03:11 AM
#2
Re: External Form Values?
My guess would be that you used the FindWindow API to get a handle to the topmost window of the application and the the FindWindowEx API to find the handles of the username and passwords fields, then the SendMessage API to set values into those fields etc.
-
Jun 26th, 2011, 03:01 PM
#3
Thread Starter
New Member
Re: External Form Values?
Thank you. This does help somewhat. I used a program that upon putting my cursor over the field (submit button, text box) it would give me the variables name or value. And from there I would use something like textBox = 'johnny' AIMtextbox = textBox. I hope this helps clarify what I was talking about a little. Thanks again and please let me know if you have any further suggestions.
-
Jun 26th, 2011, 03:10 PM
#4
Re: External Form Values?
What Doogle was getting at I believe, is that VB cannot do this without APIs.
1. You have to locate the top-level target window. Which means you have to have some information about that window, like it's caption, class name, handle or something else that would allow you to a) determine if it's even present and b) distinguish it from other similar windows
2. Then you'd have to search its children, grand children, etc until you found the specific target window(s) you are looking for. Again, these must be distinguishable either by class name, ID (not all windows have IDs), caption, or something else
3. If the target windows are textboxes, then you'd use SetWindowText or SendeMessage APIs to populate the textboxes. In order to use those APIs, you need the target hWnd, which is why the 1st two steps must be completed successfully.
Now your app you were talking about, did most of this stuff behind the scenes. On the GUI, sure you may have just had to enter a little information, including what to set the textbox values at, but behind the GUI is where the above logic and APIs would have been used.
You can search this forum for more help, using terms like: remote click or control another app
-
Jun 26th, 2011, 03:31 PM
#5
Thread Starter
New Member
Re: External Form Values?
Thanks for your help yall. I was looking for the handles of other windows and the program with a GUI that identifies these handles. I found a link to said program in this site. Yall have been very helpful, thanks again.
-
Jun 27th, 2011, 01:19 AM
#6
Re: External Form Values?
I was putting a simple example together
Program 1:
Code:
Option Explicit
Private Sub cmdLogon_Click()
If txtUsername.Text = "Username" And txtPassword.Text = "Password" Then
MsgBox "Logon Successful"
End If
End Sub
Private Sub cmdLogon_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Debug.Print "Mouse Down"
End Sub
Private Sub cmdLogon_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Debug.Print "Mouse Up"
End Sub
Private Sub Form_Load()
txtUsername.Text = ""
txtPassword.Text = ""
Me.Caption = "Doogles Folly"
End Sub
Just a Form with a couple of textboxes (txtUsername, txtPassword) and a commandbutton (Caption = Logon)
Program2
Code:
Option Explicit
Private Const WM_SETTEXT As Long = &HC&
Private Const BM_CLICK As Long = &HF5&
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
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 SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Sub cmdSend_Click()
Dim lngMain As Long
Dim lngChild As Long
Dim lngReturn As Long
lngMain = FindWindow(vbNullString, "Doogles Folly")
If lngMain <> 0 Then
lngChild = FindWindowEx(lngMain, 0&, vbNullString, "txtUsername")
If lngChild <> 0 Then
SendMessage lngChild, WM_SETTEXT, 0&, ByVal "Username"
CloseHandle lngChild
lngChild = FindWindowEx(lngMain, 0&, vbNullString, "txtPassword")
If lngChild <> 0 Then
SendMessage lngChild, WM_SETTEXT, 0&, ByVal "Password"
CloseHandle lngChild
lngChild = FindWindowEx(lngMain, 0&, vbNullString, "Logon")
If lngChild <> 0 Then
SendMessage lngChild, BM_CLICK, 0&, 0&
' SendMessage lngChild, BM_CLICK, 0&, 0&
CloseHandle lngChild
End If
End If
End If
CloseHandle lngMain
End If
End Sub
The idea being that you run Program1 and then Program2 which populates the two textboxes and clicks the CommandButton in Program1.
The interesting thing I found is that the BM_CLICK message causes MouseDown and MouseUp events for the CommandButton but the _Click event is not triggered. Sending BM_CLICK twice does cause the _Click event to trigger.
I guess there's a reason for that - but I don't know what it is
Last edited by Doogle; Jun 27th, 2011 at 05:38 AM.
-
Jun 27th, 2011, 12:53 PM
#7
Re: External Form Values?
 Originally Posted by Doogle
...The interesting thing I found is that the BM_CLICK message causes MouseDown and MouseUp events for the CommandButton but the _Click event is not triggered. Sending BM_CLICK twice does cause the _Click event to trigger.
I guess there's a reason for that - but I don't know what it is 
P.S. I fiind it more reliable to send the parent a WM_Command message with a BN_CLICKED submessage. Requires a bit more code:
1. Get target handle of button
2. Get its Parent: GetParent API
3. Get button's control ID: GetWindowLong API with GWL_ID parameter
4. SendMessage or SendMessageTimeOut API to parent:
SendMessage buttonParentHWnd, WM_COMMAND, BtnCtrlID, ByVal BtnHWnd
Regarding failure with BM_CLICK, here's what MSDN says
If the button is in a dialog box and the dialog box is not active, the BM_CLICK message might fail. To ensure success in this situation, call the SetActiveWindow function to activate the dialog box before sending the BM_CLICK message to the button.
Edited: Why are you using CloseHandle? It isn't appropriate for FindWindow/FindWindowEx. FindFirstFile, sure.
Last edited by LaVolpe; Jun 27th, 2011 at 01:02 PM.
-
Jun 27th, 2011, 01:45 PM
#8
Re: External Form Values?
 Originally Posted by LaVolpe
Edited: Why are you using CloseHandle? It isn't appropriate for FindWindow/FindWindowEx. FindFirstFile, sure.
You're absolutely right. Just my age,I think
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|