472,127 Members | 2,108 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 software developers and data experts.

Auto-Login on a WebBrowser?

I'm trying to create a program to automatically log me in to Myspace. Yes, I am too lazy to login myself!

And sorry, but I'm not exactly using a WebBrowser, but something that's name is "SHDocVw" that I got by adding a reference to something for my project... And I have also added a reference to "Microsoft HTML Object Library".

I wrote the following code to edit the text in the "username" box on the Myspace home page.

Expand|Select|Wrap|Line Numbers
  1. Private Sub SetTextboxText(ByVal Text As String)
  2.         DirectCast(GetCurrentWebForm.item("namehere"), mshtml.HTMLInputElement).value = "myemail"
  3.     End Sub
Then I wrote the following code, this time using a new project with a WebBrowser, to provide the names of the elements I would need to use from the Myspace home page.

Expand|Select|Wrap|Line Numbers
  1. Dim hdoc As HtmlDocument = Me.WebBrowser1.Document
  2.         Dim elemcoll As HtmlElementCollection = hdoc.GetElementsByTagName("input")
  3.         For Each helement As HtmlElement In elemcoll
  4.         If Not helement.GetAttribute("Type") = "hidden" Then
  5.         Me.TextBox1.Text = TextBox1.Text & Environment.NewLine & helement.Name
  6.         End If
  7.         Next
It provided the names of the username and password box that I would need to fill out.

So I modified the first code to fill the Username box with my email, but when I tested it out, the project became unresponsive for a couple seconds and then came with an error that "vshost.exe has encountered an error and needs to close....blah blah blah".

Can anyone help me out with this problem? I have been stumped on it for many days!!! If you can also help me figure out how to click the "Login" button on the homepage that would be helpful too! I'm using Visual Basic 2005 & Visual Basic 2008.

Personally, I believe that the problem is that the login form on the Myspace homepage may not be composed of a typical textbox or button. I think this because I tried my code out on the Google Homepage (to enter text and click "Search" button) and it worked like a charm. Or perhaps I need to provide an index in the code? Any help?

Oh, and I am using a computer running Windows XP.

Here is some more source code from my project to help explain some of the above:

Expand|Select|Wrap|Line Numbers
  1. Private Function GetCurrentWebDoc() As mshtml.HTMLDocument
  2.         Try
  3.             Return DirectCast(wb.Document, mshtml.HTMLDocument)
  4.         Catch ex As Exception
  5.             Return Nothing
  6.         End Try
  7.     End Function
  8.  
Expand|Select|Wrap|Line Numbers
  1.     Private Function GetCurrentWebForm() As mshtml.HTMLFormElement
  2.         Try
  3.             If GetCurrentWebDoc.forms.length > 0 Then
  4.                 Return DirectCast(GetCurrentWebDoc.forms.item(0), mshtml.HTMLFormElement)
  5.             Else
  6.                 Return Nothing
  7.             End If
  8.         Catch ex As Exception
  9.             Return Nothing
  10.         End Try
  11.     End Function
Jun 24 '08 #1
0 1768

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Manlio Perillo | last post: by
5 posts views Thread by Robert Downes | last post: by
20 posts views Thread by Vijay Kumar R. Zanvar | last post: by
5 posts views Thread by maya | last post: by
22 posts views Thread by nospam_news | last post: by
2 posts views Thread by Piotr K | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.