How to Login To Gmail and Facebook With VB Form

In this article you will learn how to login into Gmail and Facebook with a VB Form.

This article shows how to  login into Gmail and Facebook with a VB Form. I have tried to provide an easy procedure showing simple code.

Create a new project.

We need:

  1. Two TextBoxes
  2. Two CheckBoxes
  3. Three Labels
  4. One Button
  5. One WebBrowser
  6. A ProgressBar

login

 Change Propertie

                           TextBox2
Change Properties

Change Properties

                           WebBrowser1
scripterror

Now go to the Gmail login page and open View Source. We need some information from here:

  1. Like <input type=”text” name=”abcd” id=”abcd”>  
Gmail login page view source:

view source

See VB code:
VB code

Facebook login page view source.

page view source

See the VB code:

See VB code

Code 
  1.     
  2.    
  3. Code:  
  4. Public Class Form1  
  5. Private Sub Form1_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load  
  6. Label3.Visible = False  
  7. End Sub  
  8. Private Sub login_gmail()  
  9. WebBrowser1.Document.GetElementById("Email").SetAttribute("value", TextBox1.Text)  
  10. WebBrowser1.Document.GetElementById("Passwd").SetAttribute("value", TextBox2.Text)  
  11. WebBrowser1.Document.GetElementById("signIn").InvokeMember("click")  
  12. End Sub  
  13. Private Sub login_facebook()  
  14. WebBrowser1.Document.GetElementById("Email").SetAttribute("value", TextBox1.Text)  
  15. WebBrowser1.Document.GetElementById("pass").SetAttribute("value", TextBox2.Text)  
  16. WebBrowser1.Document.GetElementById("loginbutton").InvokeMember("click")  
  17. End Sub  
  18. Private Sub Button1_Click(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles Button1.Click  
  19. If CheckBox1.Checked = True Then  
  20. login_gmail()  
  21. End If  
  22. If CheckBox2.Checked = True Then  
  23. login_facebook()  
  24. End If  
  25. End Sub  
  26. Private Sub CheckBox1_CheckedChanged(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged  
  27. CheckBox2.Checked = False  
  28. TextBox1.Text = ""  
  29. TextBox2.Text = ""  
  30. Label3.Visible = True  
  31. WebBrowser1.Navigate("https://accounts.google.com/ServiceLogin?service=mail&continue=https://mail.google.com/mail/")  
  32. End Sub  
  33. Private Sub CheckBox2_CheckedChanged(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged  
  34. CheckBox1.Checked = False  
  35. TextBox1.Text = ""  
  36. TextBox2.Text = ""  
  37. Label3.Visible = True  
  38. WebBrowser1.Navigate("https://www.facebook.com/")  
  39. End Sub  
  40. Private Sub WebBrowser1_ProgressChanged(ByVal sender As ObjectByVal e As System.Windows.Forms.WebBrowserProgressChangedEventArgs) Handles WebBrowser1.ProgressChanged  
  41. Try  
  42. ProgressBar1.Maximum = e.MaximumProgress  
  43. ProgressBar1.Value = e.CurrentProgress  
  44. Label3.Text = "Loading"  
  45. If ProgressBar1.Value = ProgressBar1.Maximum Then  
  46. Label3.Text = "Done"  
  47. ProgressBar1.Value = ProgressBar1.Maximum  
  48. End If  
  49. Catch ex As Exception  
  50. Label3.Text = "Error Loading"  
  51. End Try  
  52. End Sub  
  53. End Class  
Run Login for Gmail:

Login for Gmail

Login for FB:

Login for FB

Thanks....