Solved

need a windows 7 script to load a webpage and automatically enter a username and password

Posted on 2015-01-24
16
386 Views
Last Modified: 2015-01-28
I'm wanting to create a script (some sort of executable file which I can place on my Win 7 desktop and execute by double-clicking it) which will:

open IE
load a pre-defined webpage (e.g. http://somedomain.com)
enter a pre-defined username in the webpage's user login form
enter a pre-defined password in the webpage's user login form
0
Comment
Question by:qeng
  • 9
  • 7
16 Comments
 
LVL 4

Accepted Solution

by:
Zsolt Pribusz earned 500 total points
ID: 40567946
You can do this easily with AutoIt.

https://www.autoitscript.com/site/autoit/

After script is captured and finalized, you can make an executable from it with Aut2Exe.
0
 

Author Comment

by:qeng
ID: 40568411
Zsolt,

Thank you for the reference.  I have started to look into it but since I have little background in scripting, it looks like I will need to spend quite a bit of time familiarizing myself with AutoIt (I downloaded the zip files but couldn't find installation instructions; there are both 32bit and 64bit versions in the zip file and the package includes a number of additional files which I'm not clear how to use/install).

What I've done in the meantime is progressively write my own VBS script which will successfully run from the desktop when double-clicking.

So far my script does the following:

- Defines my desired page URL (say "https://mypage.com)
- Triggers IE and loads my URL
- Defines the Username and Password I will want to pass to the webpage
- Defines the first (static) portion of a secure token (say 'secureToken_firstHalf') i will need to pass to the webpage
- Requests the second (dynamic) portion of the secure token (say 'secureToken_secondHalf') from the User
- Defines the SecureToken I will need to pass to the webpage by concatenating secureToken_firstHalf & secureToken_secondHalf

What I don't know how to do is then, on the secure webpage my script has opened:

- enter (pass) the Username into the Username input box
- enter (pass) the Password into the Password input box
- enter the SecureToken into the Secure Token input box

When I inspect the DOM element on the secure webpage I'm logging into (I have to do this several times a day, hence why I want to automated it) it shows:

for the Username input box:

<input name="username" id="username_5" type="text" size="20">

for the Password input box:

<input id="password_5" type="password" name="password" size="20">

for the SecureToken input box:

<input id="password#2_5" type="password" name="password#2" size="20">


I'm thinking there is something like a getElementbyID function? with a submit? or something but I'm not proficient enough to code this yet.
0
 

Author Comment

by:qeng
ID: 40568414
I should have added that the last step I'm trying to accomplish after passing the log-in credentials is to automatically click the 'Log-In' button on the same page.

The Log-In button shows up this way on the webpage:

<input id="btnSubmit_6" type="submit" value="Log In" name="btnSubmit">
0
 
LVL 4

Assisted Solution

by:Zsolt Pribusz
Zsolt Pribusz earned 500 total points
ID: 40568500
In  AutoIT I think it needs to look like this:

$sPasswd = InputBox("Security Check", "Enter your SecureToken.", "", "*")
Run("C:\Program Files\Internet Explorer\iexplore.exe http://YOURSITE.COM/LOGINPAGE")
WinWaitActive("YourPageTitle - Internet Explorer","")
Send("{TAB}{TAB}USERNAME{TAB}PASSWORD{TAB}"
Send($sPasswd)
Send("{TAB}{ENTER}")

Open in new window


You need to change the site address in second row.
In next row you need to change your ie window title (This can be get with AutoIt v3 Window Info tool)
In next rows you need to define the keystrokes, you need to do to login.

In my example, if page is loaded, you need to hit two tab key to get into username box, then another tab to get into password box, and one more tab to enter your secure token, and one more tab key to highlight the login button, and send an enter key finally.
0
 

Author Comment

by:qeng
ID: 40568560
Thanks Zsolt but I'm not using AutoIT yet.  I'm simply coding in VBS using Notepad (e.g. creating a script file on my desktop, say mySript.VBS, and executing by double clicking it).

What would the VBS commands be to target the input boxes on the webpage I described above?
0
 
LVL 4

Expert Comment

by:Zsolt Pribusz
ID: 40568586
Sorry I'm not good with VBS. If you want to do this only in VBS, then someone else need to help you.
But since everything you want, can achieve with AutoIt in seconds (you just need to adapt the script I wrote to your environment), why you not try it out?
0
 

Author Comment

by:qeng
ID: 40568633
Zsolt,

Thank you for staying with me on this.  There were a couple of reasons I wanted to do this only in VBS.  The first one is that I don't know how to use AutoIt.  I did download it but I'll need to learn how to use it.  The second and main reason is that I probably won't be able to use AutoIt on my work computer (where I also intend to use the VBS script) since I don't have administrator privileges to install AutoIt.  I suspect that AutoIt probably lets me compile the script into a VBS script but again this is something I don't know how to do.

What I've managed to do so far using VBS alone (using statements like '.getElementByID("username_5").value = "myusername") is to successfully log into the first page of the remote computer.  Which means I was able to pass the Username, Password, Secure Token and to submit the form (equivalent to clicking the LogIn button).

But now I have to make my script target a link on this new page and I don't know how to do that :) ... yet.  The whole log-in process is annoyingly time consuming because it involves several log-in pages; that's why I'm trying to automate it.

Are you able to refer me to one of your colleagues with more VBS experience?
0
 
LVL 4

Assisted Solution

by:Zsolt Pribusz
Zsolt Pribusz earned 500 total points
ID: 40568657
I Think you need to ask for VBS help in programing section.

AutoIt installation is easy, just download the installer and run it.
Compiling the script into exe is also easy thing. If i remeber correctly you just need to press F7 in the editor to make a portable executable. To run this executable on another computer, you dont need to install autoit sooftware there.

AutoIt more like an advanced macro recorder and player with programming logic. There is a recorder in extras what you can use to capture your actions (mouse, keyboard and other activities).
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:qeng
ID: 40568666
Where I'm at at the moment is my script gets me logged in on the first page, and the second page loads.

On the second page (which I don't know how to target in my script; it becomes the active tab in IE) there is a link which doesn't have an id which I need to 'click' on.

The link is in a table and looks like this:

<table width="100%" id="thetableid" border="0" cellspacing="0" cellpadding="4">
                        <tbody><tr valign="top">
                          <td><img width="18" some code here" border="0"></td>
                          <td width="100%" align="left">
<a href="/somelabel/somelabel2/winlaunchterm.cgi?row=1&amp;index=0&amp;perm=no">sometext</a>                          </td>
                        </tr>
                      </tbody></table>


The link I'm trying to 'click' on from within the script is:
<a href="/somelabel/somelabel2/winlaunchterm.cgi?row=1&amp;index=0&amp;perm=no">sometext</a>

I'm thinking it will look something like:  .getElementByID("thetableid").click() or something like that but I suspect I need some code ahead of that to set the object first and define which of the tabs is the active tab (or define that the current tab is the one I'm needing to target).
0
 

Author Comment

by:qeng
ID: 40568669
Zsolt,

Thank you.  I suspected as much but will try to finish my present VBS script before heading into AutoIt.

I'm making progress, albeit slowly, learning as I go.  I'll close out this question and post a new one to continue where I left off.
0
 

Author Closing Comment

by:qeng
ID: 40568674
The expert did his best to assist.  The solution required the use of 3rd party software (free) which I'm not familiar with.  I required a solution in VBS script.  I will repost.
0
 
LVL 4

Expert Comment

by:Zsolt Pribusz
ID: 40569431
One more thing come to my mind. On second page, the link what you need to click is dynamically changing? If not, then just hardcode that link into your script to open it with IE. Since login is done already, it should work.
0
 

Author Comment

by:qeng
ID: 40572324
Good call Zsolt.  That idea came to me as well and that's what I had done.

I managed to automate through the two login screens of the Junos Pulse Secure Access Service all the way through startup of the Terminal Session.

The last few pieces I need to add to my script are:

add a delay
send a return keystroke
add a delay
send a return keystroke
send a password
send a return keystroke
0
 
LVL 4

Expert Comment

by:Zsolt Pribusz
ID: 40572707
I think this will be piece of cake for you now :)
0
 

Author Comment

by:qeng
ID: 40574730
Thanks Zsolt,

I got the last pieces working ( used WshShell.SendKeys "{ENTER}" etc. along with delays where I thought I needed them), but ...

The problem I have left is that the correct keystrokes seem to be getting sent but they are not sent into the Terminal Session my script got me logged into, they are sent to the original desktop session where my script started executing (this is likely not the correct IT terminology but you get my drift).

Do you have any idea how I can target the sent keystrokes to be applied to the Terminal Session which Junos Pulse Secure Access Service started after my script logged me in.
0
 
LVL 4

Expert Comment

by:Zsolt Pribusz
ID: 40574898
I think, you can achieve this, by finding out the title of Junos window, and switch to it with AppActivate.
Check Microsoft article about this: https://technet.microsoft.com/en-us/library/ee156592.aspx
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

New Windows 7 Installations take days for Windows-Updates to show up and install. This can easily be fixed. I have finally decided to write an article because this seems to get asked several times a day lately. This Article and the Links apply to…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now