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:
- Two TextBoxes
- Two CheckBoxes
- Three Labels
- One Button
- One WebBrowser
- A ProgressBar
Change Propertie
TextBox2
Change Properties
WebBrowser1
Now go to the Gmail login page and open View Source. We need some information from here:
- Like <input type=”text” name=”abcd” id=”abcd”>
Gmail login page view source:See VB code:Facebook login page view source.See the VB code:
Code
-
-
- Code:
- Public Class Form1
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- Label3.Visible = False
- End Sub
- Private Sub login_gmail()
- WebBrowser1.Document.GetElementById("Email").SetAttribute("value", TextBox1.Text)
- WebBrowser1.Document.GetElementById("Passwd").SetAttribute("value", TextBox2.Text)
- WebBrowser1.Document.GetElementById("signIn").InvokeMember("click")
- End Sub
- Private Sub login_facebook()
- WebBrowser1.Document.GetElementById("Email").SetAttribute("value", TextBox1.Text)
- WebBrowser1.Document.GetElementById("pass").SetAttribute("value", TextBox2.Text)
- WebBrowser1.Document.GetElementById("loginbutton").InvokeMember("click")
- End Sub
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- If CheckBox1.Checked = True Then
- login_gmail()
- End If
- If CheckBox2.Checked = True Then
- login_facebook()
- End If
- End Sub
- Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
- CheckBox2.Checked = False
- TextBox1.Text = ""
- TextBox2.Text = ""
- Label3.Visible = True
- WebBrowser1.Navigate("https://accounts.google.com/ServiceLogin?service=mail&continue=https://mail.google.com/mail/")
- End Sub
- Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
- CheckBox1.Checked = False
- TextBox1.Text = ""
- TextBox2.Text = ""
- Label3.Visible = True
- WebBrowser1.Navigate("https://www.facebook.com/")
- End Sub
- Private Sub WebBrowser1_ProgressChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserProgressChangedEventArgs) Handles WebBrowser1.ProgressChanged
- Try
- ProgressBar1.Maximum = e.MaximumProgress
- ProgressBar1.Value = e.CurrentProgress
- Label3.Text = "Loading"
- If ProgressBar1.Value = ProgressBar1.Maximum Then
- Label3.Text = "Done"
- ProgressBar1.Value = ProgressBar1.Maximum
- End If
- Catch ex As Exception
- Label3.Text = "Error Loading"
- End Try
- End Sub
- End Class
Run Login for Gmail:Login for FB:Thanks....