How to load webpage in VB and automatically log in? - vb.net

I have an application that will open a webpage using the Web browser control and automatically login the users information, for example gmail. I plan on having 3 choices the user can enter: Gmail, Twitter and Facebook. All the do it type in their username and password and click one of the options above, and their account will automatically be signed in. The problem I am experiencing is that when my application loads, so does gmail, so if the user wants to login to facebook, it would be awkward to see Gmail automatically loaded in the form instead, right? So I took ` WebBrowser1.Navigate("https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1&ltmpl=default&ltmplcache=2&emr=1&osid=1") from the private form, and wanted to add it into my button called gmail. So the button would look like this:
Private Sub btnGmail_Click(sender As Object, e As EventArgs) Handles btnGmail.Click
WebBrowser1.Navigate("https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1&ltmpl=default&ltmplcache=2&emr=1&osid=1")
WebBrowser1.Document.GetElementById("Email").SetAttribute("value", txtEmail.Text)
WebBrowser1.Document.GetElementById("Passwd").SetAttribute("value", txtPasswd.Text)
WebBrowser1.Document.GetElementById("signIn").InvokeMember("click")
End Sub
However I get the error:
An unhandled exception of type 'System.NullReferenceException'
Which from some Googling showed that it meant there was something NULL in my form? But everything is filled in, so I don't understand why? In my code, it underlines the "txtEmail.Text" part on the 3rd line, but I'm filling it in?
So now I am left clueless as to have the user click the button "GMAIL" so it will load gmail and proceed to input the information they type in the email and passwd textbox.

Related

VB - Form 2 closes automatically whenever Form 1 closes?

So right now, I'm so frustrated because there is ONE little problem that stops me from continue working on my programm.
I made a simple Login Form where the user must type in a password and when he failed after 3 attempts, the form will close. BUT if the user enters a correct password, a button will become visible and he can Login and another Form with the main programm will open. So I want to close the Login Form when the user presses the Login button and the Form 2 will appear. Simple Code:
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
logint = 1
Form2.Show()
Me.Close()
logint handels the attempt counter... WHATEVER.. the MAIN PROBLEM is, that whenever I press Login the Login closes instantly and the form 2 pops up, stays for like 2 Seconds and closes right after that. I searched both codes and there is no "Form2.Close() " or "Me.Close()" which could cause that error. Form 2 always exits with Code 0 (0x0). What can I do if I want just the Login Form closed and the Main form loaded?
If you right click on your project and select the Propeties voice from the Popup menu and switch to the Application page you will notice a combobox that says:
Shutdown mode = When Startup Form close.
Your startup form is the Login form, so when it closes your app terminates.
You can change this settings to
Shutdown mode = When last form closes.
However, pay attention to not have orphaned forms around your application otherwise it will never stop.
A better approach is to start your application with the normal form and in its constructor execute the login form. If the login form doesn't allow your application to continue, set a global variable and Close the main form in its Load event.

vb.net if statement on webbrowser control

Morning! (atleast in the US its morning).
I have an app with multiple buttons that load different sites using the webbrowser control. I have the below code to auto login to an email website. However, if I browse to another site and then click the email signin button to execute the below code, it errors out. It errors out because it already signed me in to the site the first time and now since the credentials are cached it logs me right in and bypasses the login page.
How do I check if the login page doesn't exist, then exit sub.
WebBrowser1.Navigate(My.Settings.emailURL)
WaitForPageLoad()
WebBrowser1.Document.GetElementById("user").InnerText = My.Settings.emailUN
WebBrowser1.Document.GetElementById("passwd").InnerText = My.Settings.emailPW
'WebBrowser1.Document.GetElementById("remember_me").SetAttribute("checked", "false")
WebBrowser1.Document.DomDocument.forms(0).submit()
I tried the below but it didn't work:
If WebBrowser1.Navigate(My.Settings.emailURL) <> My.Settings.emailURL
Im assuming it didn't work because its a navigate command
Figured it out. The web address is unique if you're signed in and displays a static web url, so I did a small if statement.
If WebBrowser1.Url.AbsoluteUri.StartsWith(My.Settings.webmailURL)
Exit Sub
Else
Sign in......
end if
Hans thanks for the help, you got me thinking.

If on URL then message box

So I have this weird problem. I have a WebBrowser starting on the page https://live.xbox.com/en-US/MyXbox/GamerProfile (It is a page for editing information on your account) but whenever it goes there it takes the user to live.com to log in, and then goes back to the page to edit his profile. This is how I want it to function, but I want a message box to display if it takes the user to the page again (to verify he's logged in). This is what I have so far:
If WebBrowser1.Url.OriginalString() = "https://live.xbox.com/en-US/MyXbox/GamerProfile" Then
MessageBox.Show("You are logged in!")
End If
But I never get the message box to show, and I don't think it works :\
Does anyone know why it isn't working?
which part of your application is that code running? I mean, does your program knows when xbox takes the webrowser to the login page and back? If your code only run once when the webbrowser object is created, then this doesn't get run.
EDIT:
In that case, the code should be within the WebBrwoser.DocumentCompleted() event. Take a look at this: http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.documentcompleted.aspx

VB.Net WebKitBrowser Enter key issue

I'm programming with vb.net 2012 and I'm having an issue with the WebKit.Net framework.
After my webkitbrowser object has loaded a page, I enter in login credentials, now the tab button gets hooked fine but when I hit enter (like people normally do on websites to login rather than actually hitting the login button) it keeps focus on another form object (tab index 0) and hits enter on that, it doesn't hook the enter button to the webkitbrowser.
I have added the following but it hasn't worked.
Private Sub WebKitBrowser2_MouseClick(sender As Object, e As MouseEventArgs) Handles WebKitBrowser2.MouseClick
Me.WebKitBrowser2.Focus()
End Sub
I'm hoping someone has a solution to this issue?

VB.Net button open multiple user and auto login in different window of IE

I have a website stored 100 users ....now i want to create a VB form with 100 buttons ....while i click button1, it will open IE then log in users1 automatic and when i click button2 , it will open IE then log in as user2 automatic. user3 until user100 the same ....click from button on vb form.
Note : i am already done to set open IE and log in as different users in each windows but now i am finding how to set auto log in with different users in the same website when i click each button in form.
i have something more about form....i will use ( 100 button click = 100 users = 100 IE window ....)
it depend on user click on button that he need to log in......because we don't know that what button/users/time will he want to click .....
I really need your help urgently...
Thank in advanced.
here is some code of Button_Click
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Using p As New Process
p.StartInfo.FileName = "C:\Program Files\Internet Explorer\iexplore.exe"
p.StartInfo.Arguments = "http://test.com"
p.Start()
End Using
This is the only way I can come up with on how to solve this.
My guess is that your login is using POST variables, it's pretty much standard.
To make this work you would have to allow the username and password to be supplied with GET. That is, sending them in the url like this:
http://test.com/login.php/asp?username=username&password=password
Since you haven't specified whether you use PHP or ASP.NET I will add info on how to get the value for both:
ASP.NET
Request.Querystring("username")
PHP
$_GET["username"];
EDIT based on comment
You are correct it is not possible to isolate separate webbrowser controls.
I would suggest you look into either WaTin to control separate IE instances, or Awsomium .NET, which i believe allows separate sessions in 1.7, though i haven't tested it.
Also be aware that since IE8 session cookies are shared across instanced by default, so you would need to run them with the -nomerge flag. WaTin supports this.
Based on the fact that you have not mentioned this in your question, i am presuming you are using IE7. If that is the case, and this application is not intended to be used on other machines, it should be possible to create a separate application with an embeded webbrowser control, then launch multiple insatances of that application from the main one, so you can add your own communication mechanism, but WaTin is probably a far better idea
OLD ANSWER:
It is very hard to work out what you want to do, but im guessing you want to create a winforms app, that lets you to choose a user account, and then open a browser and login to a website with that account.
Based on that assumption, my suggestion would be to have one button, and some way of selecting the account, say a comboBox, and a webbrowser control:
http://img198.imageshack.us/img198/888/66649645.jpg
Rather than 1 button per user account and trying to manipulate an external browser.
If this is indeed what you want to do, comment and i will edit my answer as required, and provide starting code if you need, but i cant do that without really undertanding what you need to do.