How-to: Create a shortcut that automatically logs in to any website

automatic loginWould you like to discover how you can make desktop shortcuts

That will automatically open and

Fill in your username and password

Then log you into any website fully automated?

Ever since I learned how to use a script to automate a browser

I have been using scripts to automate and log in to websites.

If you also see the benefit in that

Then in this tutorial:

I will show you step by step how you can easily make shortcuts that automatically login.

At the end of this post, you can get the script as a free download

 

Degree of difficulty:

level 5

In this tutorial we will make a script using the free scripting language AutoHotkey, it will open and log you in using the Internet Explorer browser.

Before we start, all you need are 2 things:

And 14 lines of plain text from this step by step tutorial.

 

Novices are recommended to have a look at this Tutorial

 

Example video: (0:21)

How-to: Create a shortcut that automatically logs in to facebook

 

Now let’s get on with the step by step on how to make a script that will automate your login to any website using Internet Explorer.

Frist I’ll just pick a site that most of us know “Facebook” but remember that you can use this how-to for almost any website.

 

The File to shortcut:

We start by making a new script

autohotkey_650x320

Now if you have AutoHotkey installed you can skip step one in this list.

How to create a new script:

  1. Download and install AutoHotkey.
  2. Right-click an empty spot on your desktop or in a folder of your choice.
  3. In the menu that appears, select New -> AutoHotkey Script.                 (Alternatively, select New -> Text Document.)
  4. Type a name for the file, ensuring that it ends in .ahk. For example: Testing.ahk
  5. Right-click the file and choose Edit Script.

Each script is just a plain text file containing commands that will be executed by AutoHotkey.exe

 

The 14 lines of text:

On the two first lines you will store your login info in two variables. ( Remember that this is a plain text file so if anyone has access to this file your password will be readable )

 

Browser object:

Then we will make a webbrowser object

For this we will use the function ComObjCreate

And then we use the browser object returned from that function

This object is then stored in the variable “web_browser”

 

A thing to note is that the web browser window starts out invisible by default

So we will set the browsers visible property to true

This way it will be visible so we can see it.

 

Now we have a visible web browser object in a variable aka “web_browser”

automatically login jszapp 1

 

Next we will use this object to navigate the IE web browser

For this we will use the browsers navigate method

Lets navigate to Facebook

 

Now the browser will navigate to the URL “www.facebook.com”

 

Waiting for a web page to load:

But for us to know how long this navigation will take

We will use another property of the browser object

The busy property, this property will be true as long as the browser is busy

So we will test for this with a while loop

This while loop will test the busy property every 100 milliseconds aka 10 times a seconds

 

After the while loop breaks we will put in a little extra sleep (wait time) to make sure any JavaScript is also done before we start

 

 

So as soon as the web browser stops being busy the while loop will break

And the script will go onto the next lines

 

So now we or the browser is done navigating to “www.facebook.com”

 

Automatically interacting with a website:

Facebook is an html document that’s now loaded in the web browser object

So for us to automate this site we will need to go through the document object

Like this “web_browser.document”

Now it’s time to automatically input our username and password

For this we will need to know what input fields to use

 

This we can do with other script tools or the browser’s build in tools

This time we will use the IE browser’s “DOM Explorer” tool

 

You do this by manually opening an Internet Explorer browser and navigate to Facebook

Now press your right mouse button over the “Email or phone” field and pick

the “Inspect element” item from the drop down menu that appears

 

This will open Explores “DOM explorer” sub window

In this window you will see a line that is selected

looking something like this

<input name=”email” tabindex=”1″ id=”email” type=”text” value=””>

 

From this line we will need the value of the “id” Attribute

So looking at this line will tell us that here the “id” is “email” so let’s use that

 

Now to use this element we will store it in a variable let’s call it “username_input”

To do this we will use the document objects getElementById function

It looks like this

That line gets the element with the id = “email” and puts it in our variable “username_input”

 

Now we can use this webpage element via our variable “username_input”

automatically login jszapp 2

 

 

Automated filling of web fields:

So to automatically fill in the value of the input field with our username

We will set the “value” property of the element to the data in our “My_User_Name” variable

So now the “email or phone” input field will hold our username

 

Next we will do the same thing for the password.

Go to www.facebook.com and move your mouse over the password input field

Now right-click it then select the “Inspect element” item from the drop down menu

This will open the DOM tool with a selected line looking something like this:

<input name=”pass” tabindex=”2″ id=”pass” type=”password”>

 

From this line we will again need the value of the “id” Attribute

so looking at this line we can tell that here the “id” is “pass” so we will use that

 

Again we take the element and store it in a variable we call “password_input”

To do this we will again use the document objects getElementById function

So it looks like this for the password

That line gets the element with the id = “pass” and puts it in our variable “password_input”

 

Ones again we can use this webpage element via our variable “password_input”

 

Okay to automate the filling in of the value of the password input field with our password

Set the “value” property of the webpage element to the data in your “My_Pass_Word” variable

So now the “password” input field will hold our password

 

Clicking an html Element:

The last thing we need to do is click the Login Button

How to do that? You say!

 

Frist we go to www.facebook.com and move our mouse over the login button

When over the login button you press the right mouse button and

select the “Inspect element” item from the drop down menu

 

This will show the login button element selected in the DOM tool

The line will look something like this:

<input tabindex=”4″ id=”u_0_n” type=”submit” value=”Log In”>

 

 

This time we just need to click the button element

So we will only use the element by its “id”, but not store it in a variable

For this we will use almost the same method as with the other elements

So we will use the document objects getElementById function again

And also the elements “click” method

It will look something like this for the login button.

That line gets the element with the id = “u_0_n” and clicks it with the “click()” method

 

Ending a script:

Now saving and running this script will open an IE browser

And navigate to www.facebook.com and then automatically login

 

automatically login jszapp 3

 

Conclusion:

That is one way to do an automated login to a website like Facebook, now you can use this method to do the same for almost any website you need, this can also be made to open by hotkey and also to automatically login to open websites and more.

 

Keep telling me if  you need more guides to make things like this or anything I missed or does this kind of post even help you out?

If you have any Questions you can always use the comments or contact page

Try it:

To use your new script, continue as follows:

  1. Save and close the file.
  2. Double-click the file to launch it.

To find, exit or edit the script, right-click the green “H” icon in the taskbar notification area.

Notes:

  • Scripts like this can also use exitapp as the ending line to not have to many scripts running simultaneously, as each will have its own icon in the taskbar notification area.
  • Username and password can also be input by the user at startup as seen in the compiled exe below.
  • To have a website launch and login automatically when you start your computer, create a shortcut to the script file in the Start Menu’s Startup folder.

 

Free downloads:

Script (.ahk)

Free – Get

Application (.exe)

Free – Get

 

 

jszadmin

Drafter and Webmaster at JSZapp.com
I’m Jackie Sztuk or JSZ. I have a Drafter’s degree from Copenhagen Technical College (KTS) and my passion for windows scripting is what makes me want to help as meny as i can by writing great and easy to follow How-to's.

jszadmin

I’m Jackie Sztuk or JSZ. I have a Drafter’s degree from Copenhagen Technical College (KTS) and my passion for windows scripting is what makes me want to help as meny as i can by writing great and easy to follow How-to's.

53 Comments:

  1. I tried this a million different ways and it simply does not work.

  2. Marvelous! Thank you so much. I wish I had seen this years ago when I was first starting with AutoHotkey.

  3. Hiya is there a way I can update information in one website and it updates in other websites as well ro save me cutting and pasting the same info over and over again.

    • Well yes,

      But there is a good amount that needs to be in place for you to do it!

      • Sure. Can you tell me how specifically this can be done as far as the good amount that needs to be in place. I want to be able to update quite a few forums that I am a member of with information so that I do not end up repeating myself over and over again.

        Many Thanks,look forward to hearing from you soon

  4. Hello,

    thanks for sharing this…
    It is also possible to login via .htaccess and .htpasswd to access an PC to download a File? The Domain uses https:// to secure the communication. (A little Bit…)

  5. Hi Jack,

    Will you help me to create multiple auto-login to 10-20 websites with using only the Firefox Browser.

    Appreciate your help.

    Thank you
    Chan

  6. Pingback: AutoHotkey Webinar: 8/30/2016

  7. nice jszadmin but i need an another help. can you give me a script for amazon which automatically clicks on buy now button of a specified product in every 10 milliseconds…. please help me……

  8. Hi Jackie,

    Thanks for this script. Before jumping into it though… Does this work with windows 10? I am a total but enthusiastic beginner so could you please help me with this? Is there still no workaround to use firefox and not explorer (or edge)? Also is private browsing an option?
    I have to login to one website with several accounts and I need either to delete the cookies before login or use incognito/private browsing.

    Thanks a lot,
    Orsi

  9. Pingback: Autohotkey COM Video Reference: Internet Explorer Basics

  10. Pingback: AutoHotkey COM Video Reference: Excel basics

  11. hi the new google login is hard to get right – can you help?

  12. Hi Jackie, thanks for the great tutorial! It works perfectly with the websites i’ve tried it with. Problem is: one website I would like to automatically log into doesn’t have an id set for the submit button. Is there a way to use getelementby… name or something?
    Thanks!!

    • Hi Alicia,

      Thanks glad you like it,

      There are a few methods like “getElementById”

      There is also
      getElementsByTagName
      getElementsByName
      getElementsByClassName

      Anyone of them can most likely be used but can’t really say without knowing more about your page 🙂

      Your welcome to send me the url if it’s a public site use the contact form

      Cheers,
      Jackie

  13. Hi there, I found your blog thru the ahk community, and since i cant make an account there, I thought maybe you could help me out figuring out my problem.

    What I’m trying to do is a script to change my IP easily, basically what it does is access my modem configuration page and change the last mac numbers to something else, making my ISP give me a new IP, but at some point, right after i login its like the object gets disconnected, and I need a function to connect back, why is that happening? Im on Win10 IE11 and here is the code:

    wb := ComObjCreate(“InternetExplorer.Application”)
    wb.Visible := True
    WinMaximize, % “ahk_id ” wb.HWND
    wb.Navigate(“http://192.168.0.1/”)
    IELoad(wb)
    wb.Document.getElementsByTagName(“input”)[0](“loginUsername”).Value := “admin”
    wb.Document.getElementsByTagName(“input”)[1](“loginPassword”).Value := “xxxxxx”
    wb.Document.getElementsByTagName(“input”)[2](“submit”).click() ;from this moment it gets disconnected and I cant use IELoad(wb) or it will be looping forever, so I use sleep
    Sleep, 1000
    wb.Navigate(“http://192.168.0.1/RgSetup.asp”) ;have to use wb.Navigate because it is disconnected and I cant click or get values from the page either.
    wb := WBGet(“Residential Gateway”) ;to connect back to the object
    hexNumber := wb.Document.getElementsByTagName(“input”)[14].Value
    MsgBox % hexNumber

    • Hi Mark,

      It’s a security feature of IE (seen it before)

      If the object is really disconnected your wb.navigate line will not work or has no use

      Most likely the submit event is what’s disconnecting it so do your sleep and then the WBGet function call

      There is no way to really get around it that i know of.

      Best you can do is what you’re doing now.

      Have you tried the cmd commands “ipconfig /release” – “ipconfig /renew”?

      Cheers,
      Jackie

      • Hey, thanks for answering and the suggestion.

        I tried those commands yes, but still, my IP doesnt give me a new IP, i heard something about lease time. But thanks!

  14. Hi Jackie,

    I read your tutorial and it works on Internet Explorer which is good. However I want to use Google Chrome for my default web browser to do the automation of log-in in a certain website.

    It is possible to use Google Chrome? if possible can you give me on how can I use it?

    Thanks more power!

  15. Ok thanks Jackie.

  16. Hello Jackie, just curious, can this also be done using C# or VB.Net, or do you have to use AutoHotKey? Thanks.

    • Hi Milli,

      You can do it in other languages to

      Depending on the language it can be more or less elegant but still doable.

      Can’t say which will be the easiest one but Autohotkey lets you do it without including anything not build-in

  17. My Facebook is already opened by Internet Explorer, the AHK must fill in the username and password fields.
    Just like you taught:

    username_input: = web_browser.document.getElementById (“email”)
    username_input.value: = Your_User_Name
    password_input: = web_browser.document.getElementById (“pass”)
    input.value password: = my_password

    There is this possibility?

    • Hi Carlos,

      One way to get a COM object of the currently open IE window
      Is to use the shell windows collection
      To loop over all the open explorer windows

      And then check the windows title or
      Other things to identify the IE window you need

      There is a nice UDF called IEGet that does this
      It is made by jethrow and can be found almost at the bottom
      Of the first post here

  18. Hello!
    Your code works great to open facebook, great explanation, congratulations!
    I work with the AHK some time, but never used it for Internet Browser, just to systems and etc.
    I tried several forms, fill in the email field and password to the facebook already open and I could not, just the way you did, open the navegardor and then fill in the fields.
    How do I get AHK fill these fields (email and password) with already open browser?
    Thank you very much for your attention and I look forward to your good will.
    Sorry typos, I’m from Brazil and do not command your language, I’m using google translator XD

  19. Thank you so much for your response, Jackie!

    I should mention that I am a beginner at AHK, so please forgive me if I ask some very basic questions.

    I copied and pasted your code and changed the “SecurID Name”, “Passcode”, “Domain\User Name”, and “Password” values to my own. I also had to comment out the sign in button because I have to append a six-digit code from a random number generator provided by the company to the end of my Passcode.

    I am still receiving the following error message:

    “Error: 0x80010108 – The object invoked has disconnected from its clients.
    Specifically: readyState
    Line#
    005: while wb.readyState!=4 || wb.document.readyState != “complete” || wb.busy
    Continue running the script?”

    I am not sure if I was supposed to change anything else…
    Please let me know.

    Thank you again,
    Katherine

    • Hi no problem happy to help,

      We’ve all been beginners so don’t sweat it,

      The code works for me up to the part where it submits the form, as I don’t have a reel login 🙂 I can’t test more then that.

      If your error is coming up after that it’s hard for me to debug…

      Maybe there’s some special coding in the live page that causes this or it loads a new windows/tab or uses frames

      Hard for me to help if that’s the case.

      If you feel there is any more information you can give me, video or something

      That will help me help you, you’re welcome to post it or send it to me…

      Cheers,
      Jackie

      ps.: Have not found any issue with the contact form and it works for others so not sure what the issue is at this point in time, i’ll keep testing.

      • Hi Jackie,

        I was just expecting the script to fill in most of the form for me, so that I can simply add in the randomly generated number and click submit. Kind of like the autofill feature when using Google Chrome.

        When I run the code, it opens up a new Internet Explorer window and navigates to the web page, but all the fields remain blank, and then I get various error messages asking if I want to “Continue running the script?” Every time I select yes, another error message pops up.

        I cannot figure it out. I wonder if it is a problem with my laptop or something.

        Thanks again,
        Katherine

  20. Hi Jackie,

    First of all, I really enjoy reading your posts. Thank you for creating this site.

    I am experiencing a lot of difficulty with your Contact form. The error message I keep receiving is “Invalid characters in POST. Possible email injection attempt”.
    Why am I getting this message over and over again?!? So, now I will try to submit my question through your comments.

    I have been trying to use your tutorial to automatically fill in a login form with my information (https://inet.bmofg.com/dana-na/auth/url_default/welcome.cgi)
    However, I kept getting the following message:

    “Error: 0x80010108 – The object invoked has disconnected from its clients.
    Specifically: document
    Line#
    011: securid_input := web_browser.document.getElementById(“username”)
    Continue running the script?”

    I tried using getElementsByName and that did not work either. Then, I found your response (http://autohotkey.com/board/topic/111639-filling-web-forms-using-com/) so I tried adapting that for my purposes, but I am still receiving similar error messages. I am using AutoHotKey 1.1.22.3.

    Any help or suggestions would be greatly appreciated.

    Thanks,
    k

    • Hi K

      Thank you for reading and commenting, Sorry to hear about your issues i’ll look into the contact form error…

      Can’t say why you’re getting a disconnect error, i tested it and i don’t seem get any kind of errors,

      getElementsByName worked for me in my short test… but I still made a small example of an alternative way to do it

      Let me know if that helps you…

      Cheers,
      Jackie

  21. Thank you very much for doing this and publishing it. I have been trying to do this for an year, and showed my the process rather than just giving an file.

  22. Having your login credentials stored in plain text is a pretty bad opsec violation. I’d discourage doing that for any service that stores or has access to any sensitive information.

    • While it’s true that if your computer is hacked, plain text passwords make the attacker’s life really easy — at that point, does it even matter? He’ll still be able to log everything you do or type anyway.

      • Hey! really nice tutorial. I want to ask some questions. After login, is there any way to find out on which page we are redirecting? and also how to select a value from dropdown?

        • Hi Muhammad,

          Thank you, glad you like it.

          Regarding your question about redirecting, I don’t know what your asking about, can you please go in to more details!

          If its a normal html Element like a < select >, then most of the time you can use theselectedIndex orValue to select one of the options by option index number or by option value.

          Example:

          Then to select option 2 “Only search in titles” you’d use one of the two from above like this

          • Thanks for your answer. Actually my first question was, after enter credentials and clicking on the submit/login button, how do we know on what html/website page we are being redirecting? Hope you understand it now.

          • Hi Muhammad,

            That’s hard to say, as it depends on the page your trying to log in to.

            Some pages have the info in the login form’s outerHtml, like facebook:

            if you look at the forms action attribute you can see what url is used to login

            That’s not the same as the url your being redirected to tho, as that’s probably done by a server side script…

            Was that along the lines of what your asking about?

          • Yep that is it. Thanks for your response.

            Thanks a lot.

  23. I was able to figure out how to get the selected option in a scrolldown box using Com in AHK. I don’t know if you’re interested or if you already–I’m sure you are an expert so this may not help you. Anyways, my line looks like this:

    wb.document.all.reason.value := Value

    I used debugger in IE. I wasn’t able to inspect element on that particular scrolldown box.

    • Great David

      Good to hear you got it working, when setting the selection of a “Select” element you may also use “.selectedIndex := 1” insted of the value

      >> I used debugger in IE. I wasn’t able to inspect element on that particular scrolldown box.

      Yeah some Elements can be hard to inspect, when that happens you may need to look at the html or code of the page to find the infomation you need.

  24. How do you use Dom to inspect the element of a box that you have to click on and make a scroll down selection. Also how do you do the same If you were to input data into a field and it generates a corresponding pop up that you have to click on. BTW I love your video and tutorial and it worked great but for some websites I’m trying to use this on it won’t work. I’m just learning from examples I see on the net

    • Hey David
      One of the problem’s with automating website’s is that there are lots of ways to do the same thing. So without knowing the way it’s done on the site you a trying to login to, it will be hard for me to give you a working answer. Sorry

      >>BTW I love your video and tutorial and it worked great

      Glad you liked it 🙂

  25. Pingback: 7 Incredibly Simple Ways to Save Time Using AutoHotkey

Leave a Reply