By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,264 Members | 1,079 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,264 IT Pros & Developers. It's quick & easy.

Auto-Login on a WebBrowser?

P: 1
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
Share this question for a faster answer!
Share on Google+

Post your reply

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