[RESOLVED] working with "Sign In - Microsoft Internet Explorer"
I am trying to work with the API Sendmessage, and its possible messages. My little project is to change
my hotmail account name in the textbox of the hotmail sign in page.( I know of allapi, and I have a spying program
to look at childs of windows,etc.
So far I have this, but it is not having any effect. I suspose from reading other threads I need to find a handle to the
particular textbox to add data.
I am using VB.NET
VB Code:
Public Class Form1
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( ByVal lpClassName As String,ByVal lpWindowName As String) As Int32
Private Declare Function GetWindow Lib "user32.dll" (ByVal hwnd As Int32, ByVal wCmd As Int32) As Int32
Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWnd1 As Int32, ByVal hWnd2 As Int32, ByVal lpsz1 As String, ByVal lpsz2 As String) As Int32
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32
Private Const WM_LBUTTONDOWN As Int32 = &H201
Private Const GW_CHILD As Int32 = 5
Private Const WM_SETTEXT As Int32 = &HC
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim title As String = "Sign In - Microsoft Internet Explorer"
Dim winclass As String = "IEFrame"
'login page
Dim winchildclass As String = "Internet Explorer_Server"
'found by spying on login page of hotmail seems to be the child
Dim handlemain As Int32
handlemain = FindWindow(winclass, title)
Dim hwndtextbox As Int32
hwndtextbox = FindWindow(winchildclass, vbNullString)
Dim han As Int32
' hwndtextbox = FindWindowEx(handlemain, 0&, [TextboxClassName], vbNullString)
' dog = GetWindow(handlemain, GW_CHILD)
Dim cat As String = "hello there"
SendMessage(han, WM_SETTEXT, Len(cat), cat)
End Sub
End Class
Re: working with "Sign In - Microsoft Internet Explorer"
You cant just send it to the parent main window. You need to use your Spy tool to see the window structure/heiarchy and use FindWindowEx to drill down the structure.
Re: working with "Sign In - Microsoft Internet Explorer"
I can't send it to the main window. OK.
I am using Winspector as a spy. Outlining the main window (not the title line or the ComboBar, ToolWindow 32) I get some hex number,with Internet Explorer_Server.
I assume based on the main window that this is the class name (without a title).
so using findwindowex i get no value if i use
VB Code:
Dim winchildclass As String = "Internet Explorer_Server"
'found by spying on login page of hotmail seems to be the
Dim handlemain As Int32
Try
handlemain = FindWindow(winclass, title)
TextBox1.Text = handlemain
Dim hwndtextbox As Int32
hwndtextbox = FindWindowEx(handlemain, winchildclass, vbNullString, vbNullString)
It does get the main window handle correct....
Re: working with "Sign In - Microsoft Internet Explorer"
I wouldnt be able to tell as I dont have the exact page link. If you post it I can doublecheck the structure.
Re: working with "Sign In - Microsoft Internet Explorer"
Re: working with "Sign In - Microsoft Internet Explorer"
Well I figured out that Internet Explorer uses a class called Internet Explorer_Server. To get that "child" window handle I have:
VB Code:
handlemain = FindWindow("IEFrame","Sign In - Microsoft Internet Explorer")
Dim hwnd As Int32
hwnd = FindWindowEx(handlemain, 0&, "Shell DocObject View", vbNullString)
hwnd= FindWindowEx(hwndtextbox, 0&, "Internet Explorer_Server", vbNullString)
' hwnd now gives the same handle # as the spy program
I still am not sure how to send WM_SetText or if there is another method to put text in the textbox of the page.
Re: working with "Sign In - Microsoft Internet Explorer"
Thats not the right approach IMO.
You need to get the Document Object of Internet Explorer.
So, i guess it is a 2 step process:
1. Connect to all running instances on Internet Explorer.
Check this code:
http://www.freevbcode.com/ShowCode.Asp?ID=1606
2. In that code, check that you get the url and Navigation events for all IE windows.
You can get the DOM object using this code:
http://www.vbcity.com/forums/topic.asp?tid=119696
Now, this document object has all what you need, each HTML tag etc
Re: working with "Sign In - Microsoft Internet Explorer"
And for textboxes inside the IE page, the FindWindow etc and other Standard Win32 API will not work.
1 Attachment(s)
Re: working with "Sign In - Microsoft Internet Explorer"
Here is some code for you.
Here you get the entire HTML page. Most striking thing is that the password is blank. M$ is getting smarter lol :)
Re: working with "Sign In - Microsoft Internet Explorer"
Yep.. webpages are different. You have to access the document model of the page and modify it like that. They have no handles....
Re: working with "Sign In - Microsoft Internet Explorer"
Great .
Alright I was beginning to suspect that after finding terms like,
VB Code:
Private Function IEDOMFromhWnd(ByVal hwnd As Long) As IHTMLDocument
Dim IID_IHTMLDocument As UUID
I just have vb.net and not an earlier version. All of the programs mentioned load up with extensions like .frm, .frx,.vbp,.cls, and .bas . I can use notepad to open them (some of them), but the how to use them is still a mystery. From above the UUID is not a possibility anymore and I can't forget at least that the ByVal must be a Int32 not a Long anymore.
It may take me awhile to get all this. It sounds fairly simple. The MSN html file shows that I should first make this:
VB Code:
Private Type UUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type
But vb.net gives me an error message and says I should use a structure instead. I do get that this has to be where my information is stored.
I get that I should aim to search for:
Document Object
I appreciate your help. My very first question would be. Is this all doable with vb.net commands or is there something I must import or declare? (Along this //it is not an API thing// I found something about adding a reference to MHTML.
:cry:
Re: working with "Sign In - Microsoft Internet Explorer"
It's definately doable in VB.Net or any other .Net language.
You probably need .Net specific API declairation.
I use APIViewer to get the declarations..
It has a .Net version also:
http://www.activevb.de/rubriken/apiv...viewereng.html
Re: working with "Sign In - Microsoft Internet Explorer"
I am using ApiViewer 2004 (on VB.NET mode). Now you are implying that this IS all done with API calls..
The plan was to find the Document object of the Internet Explorers that are opened and then changing the data in these objects to change the web pages (adding data to input fields, etc.). The examples you provided are in earlier versions of vb that I do not have (or know how to examine properly).
How do I get the Document object to an Internet Explorer? (Using VB.NET)...
:confused:
Re: working with "Sign In - Microsoft Internet Explorer"
I solved this myself... finally. On my quest I noticed quite a number of questions along this path. With VB.NET being different then earlier versions it has been difficult so here is the solution.
First You need a reference to MSHTML.dll . I am not sure if this is really needed in the newest version of VB.NET. But I know somehow my version has it now.
Using the above API or whatever we can move a URL to a WebBrowser that we can put on a Form from the Toolbox.
Then this is the rest...
VB Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
WebBrowser1.Navigate("http://login.passport.net/uilogin.srf?lc=1033&id=2")
End Sub
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
Dim Page As HtmlDocument
Page = WebBrowser1.Document
Page.GetElementById("passwd").InnerText = "123456"
Page.GetElementById("SI").InvokeMember("click")
End Sub
End Class
1. The Form_Load shows how to load a page onto the form.
2. The next thing to be sure of is to remember that the page will take a few moments to load. You can put in a timer but there is an event for DOCUMENT COMPLETED. Put the next part of the code in the section for when you are sure the Web Page has been loaded.
3. HTML is just a strict version of XML and Microsoft added "HTMLDocument" to work with their WebBrowser Code.
4. So Far I need to look through the text output of the source code of a HTML page to get the Elements or Tag Names. I searched through the Text of HTML of the page for the word "INPUT". All textboxes, buttons. etc are tagged as Inputs. You need to find name="*****" and the "*****" is the Id of the element you want. For more help.....the buttons on the web page have text located on each button. The HTML will list it as value = "Sign In"
or value="text on button".
5. The .innertext changes the values on the HTML page in the quotes.
6 Finally to push a button programmatically I found you invoke an event for the element. Buttons need to be "click" (ed). (((I believe those of you who use the correct Semantics here will note that I have to invoke a method.)))