Useful Tips and Tricks
  • Blog
  • Other
  • OS
  • Powershell
  • Login

VBS script - Login to website automatically..

7/15/2011

7 Comments

 
>>>A script that will :

1) open a https://xyz.com/login page

2) provide user name and password information

3) check whether the authentication was successful or not or the web page is opening up

4) store the results got in step 3) in a log file
'----------------------script starts-----------------------------------------------------
'1)

DIM oIE

Set oIE = CreateObject("InternetExplorer.Application")
oIE.navigate "https://xyz.com/login"
oIE.Visible = True

n = 0
Do while oIE.Busy or n = 101
  n = n + 1
  WSH.Sleep 50
Loop
if n = 101 then wsh.echo "ERROR" : wsh.quit 1

'2)

Set UID = oIE.document.all.IDToken1
UID.value = "theUserID"

Set PWD = oIE.document.all.IDToken2
PWD.value = "thePassword"

oIE.document.all.btnSubmit.click

'3)
sLocation = "*ERROR*"
n = 0
Do until oIE.document.ReadyState = "complete" or n=100
  n=n+1
  WSH.Sleep 50
Loop

sLocation = lcase(unescape(oIE.document.location))

set oLogfile = CreateObject("scripting.filesystemobject").opentextfile("d:\someplace\logfile.txt", 8, true)
if not sLocation = "https://xyz.com/the/expected/destination_page.ext" then
  oLogfile.writeline "Login failed"
else

'4)
   oLogfile.writeline "You made it to " & sLocation

end if

'----------------------script ends-------------------------------------------------------
>>>Save the above script in a txt file and save as "xxxx.vbs" (double click to execute the file).

You need to change the url and designations for the elements IDToken1 (the user ID control), IDToken2 (password control) and the submit button (btnSubmit).  I am certain they will be different than those I used in my example.  Open the source (right click and click 'View Source') for the target login page and search for the correct controls.

Now you can include this script file to startup menu or scheduler to login to your website as needed.

7 Comments
Active
7/15/2011 11:31:22 am

You can also try this.login to the website based on TAB positions:

Set IE = CreateObject("InternetExplorer.Application")
set objShell = WScript.CreateObject("WScript.Shell")
IE.Navigate "website url here.asp"
IE.Visible = True
Wscript.Sleep 6000
WScript.Sleep 100
objShell.SendKeys "username"
WScript.Sleep 100
objShell.SendKeys "{TAB}"
WScript.Sleep 100
objShell.SendKeys "password"
WScript.Sleep 100
objShell.SendKeys "{ENTER}"
WScript.Sleep 100
objShell.AppActivate "IE"
objShell.SendKeys "{ENTER}"
WScript.Sleep 1000
objShell.SendKeys "{TAB}"
WScript.Sleep 100
objShell.SendKeys "{TAB}"
WScript.Sleep 100
objShell.SendKeys "{TAB}"
WScript.Sleep 100
objShell.SendKeys "{TAB}"
WScript.Sleep 100
'objShell.SendKeys "{ENTER}"

Reply
chester seo link
9/24/2012 06:57:08 am

I am happy to find this content very helpful and informative for me, as it contains lot of accurate detailing about the topic, which I was searching for. Thanks a lot and good luck.

Reply
seo nottingham link
12/6/2012 06:18:50 pm

I changed the url and designations for those elements but it doesn't work at my end, no idea why unfortunately..

Reply
MCPD link
4/29/2013 04:04:11 pm

Getting an MCITP certification implies and validates the fact that you are equipped with required knowledge and relevant experience in utilizing the products and solutions of Microsoft.

Reply
metinhoca
11/12/2015 09:40:25 pm

Hi. This is a very old topic but I hope someone can hear me. My question is that how can I do the same thing for a desktop application which has a logon screen.

Reply
Test.py link
11/20/2020 05:23:43 am

Test

Reply
Meredith O link
10/19/2024 11:24:39 am

Thanks for sharing this

Reply



Leave a Reply.

    Archives

    April 2015
    March 2015
    January 2015
    August 2014
    July 2012
    September 2011
    August 2011
    July 2011
    June 2011
    January 2011

    Categories

    All
    All
    Antivirus
    Scripts
    Seo

    RSS Feed


    Links
    • http://www.w3schools.com/
    • http://www.filehippo.com/ 
    • http://www.keygenguru.com/ 

Powered by Create your own unique website with customizable templates.