Link to home
Start Free TrialLog in
Avatar of bfuchs
bfuchsFlag for United States of America

asked on

Looking for script to auto open site with credentials filled in.

Hi Experts,
I would like to have a script/function that opens the following site
https://pages.caspio.com/login/bridgelogin/default.aspx?_ga=2.157757818.1116850724.1518037460-1462101065.1512014265
fills in the account, username and password.
See attached.
Should either be done thru Access VBA or via script.
Thanks in advance.
Untitled.png
Avatar of rastoi
rastoi
Flag of Slovakia image

on page you want to logon, there is quite nice job done from developer side to avoid robots click trough. Anyhow, it is possible and here is the powershell script to open yuor internet explorer, pass the credentials and click login. I have not proper credentials, so get only invalid account, please fill variables in first lines and test on your side
$login='account_ID'
$user='username'
$password='pa$$word'

Add-Type -AssemblyName System.Windows.Forms
Add-Type @"
 using System;
 using System.Runtime.InteropServices;
 public class StartActivateProgramClass {[DllImport("user32.dll")][return: MarshalAs(UnmanagedType.Bool)] public static extern bool SetForegroundWindow(IntPtr hWnd);}
"@

$ie = New-Object -ComObject InternetExplorer.Application
Do {Start-Sleep 1} Until (!($IE.Busy))
$ie.Navigate('https://pages.caspio.com/login/bridgelogin/default.aspx?_ga=2.157757818.1116850724.1518037460-1462101065.1512014265')
Do {Start-Sleep 5} Until (!($IE.Busy))
$ie.Visible=$true
[void] [StartActivateProgramClass]::SetForegroundWindow($ie.HWND)
($ie.Document.getElementsByTagName('a')|? {$_.classname -eq 'AdvancedUserLink'}).click()
([System.__ComObject].InvokeMember('getElementById',[System.Reflection.BindingFlags]::InvokeMethod,$null,$ie.document,'AccountName')).value=$login
([System.__ComObject].InvokeMember('getElementById',[System.Reflection.BindingFlags]::InvokeMethod,$null,$ie.document,'Username')).value=$user
([System.__ComObject].InvokeMember('getElementById',[System.Reflection.BindingFlags]::InvokeMethod,$null,$ie.document,'Password')).value=$password
([System.__ComObject].InvokeMember('getElementById',[System.Reflection.BindingFlags]::InvokeMethod,$null,$ie.document,'AccountName')).focus()
[System.Windows.Forms.SendKeys]::SendWait(" {BS}")
([System.__ComObject].InvokeMember('getElementById',[System.Reflection.BindingFlags]::InvokeMethod,$null,$ie.document,'Username')).focus()
[System.Windows.Forms.SendKeys]::SendWait(" {BS}")
([System.__ComObject].InvokeMember('getElementById',[System.Reflection.BindingFlags]::InvokeMethod,$null,$ie.document,'Password')).focus()
[System.Windows.Forms.SendKeys]::SendWait(" {BS}{Enter}")

exit

Open in new window


of course, for real life I would save encrypted password into file and decode only for login (using powershell securestring, but it is for another question ;-)
Small small trouble can occure, if you (or some other application) change the focus during logon, but password is protected from displaying on such event.
Avatar of bfuchs

ASKER

Hi Rastoi,

First thanks for the work.
Was not at work yet.
Will soon test it & reply.

Thanks,
Ben
Avatar of bfuchs

ASKER

Hi,
I saved as .ps1, then opened with notepad and put the credentials.
Now when run as powershell nothing happens.

Thanks,
Ben
Hi Ben,
How are you running it? In console?
Really nothing no error, no message, just ends?
Avatar of bfuchs

ASKER

By right click, choose run as powershell.
Not really familiar with powershell..
A black screen pops up but closes after a few sec..

Thanks,
Ben
Please, open powershell console i.e. start/run: powershell
Start saved script by using full path  to file, and put result here together with informatio which version of operating system ate you using.
In my timezone is 1pm now, so I will check in about 8 hours.
Avatar of bfuchs

ASKER

Hi,
See attached error when followed steps above.
Thanks,
Ben
Untitled.png
Avatar of bfuchs

ASKER

Actually I got that above fixed.
Now it did tried to connect but got the attached errors.

Thanks,
Ben
Untitled.png
Avatar of bfuchs

ASKER

Hi,

OK I realized that guess during this weekend they changed somehow their login screen.
Currently this is how it looks
https://id.caspio.com/?_ga=2.154520880.944330641.1518404630-2087572457.1512014159
See attached.
Note- Instead of AccountID user name and password, they now require email and password.
Perhaps we just need to modify your code accordingly..

Thanks,
Ben
Untitled.png
Avatar of bfuchs

ASKER

Did try updating as follows.
$login='***'
$user='MyEmail'
$password='MyPwd'

Add-Type -AssemblyName System.Windows.Forms
Add-Type @"
 using System;
 using System.Runtime.InteropServices;
 public class StartActivateProgramClass {[DllImport("user32.dll")][return: MarshalAs(UnmanagedType.Bool)] public static extern bool SetForegroundWindow(IntPtr hWnd);}
"@

$ie = New-Object -ComObject InternetExplorer.Application
Do {Start-Sleep 1} Until (!($IE.Busy))
$ie.Navigate('https://pages.caspio.com/login/bridgelogin/default.aspx?_ga=2.154520880.944330641.1518404630-2087572457.1512014159')
Do {Start-Sleep 5} Until (!($IE.Busy))
$ie.Visible=$true
[void] [StartActivateProgramClass]::SetForegroundWindow($ie.HWND)
($ie.Document.getElementsByTagName('a')|? {$_.classname -eq 'AdvancedUserLink'}).click()

([System.__ComObject].InvokeMember('getElementById',[System.Reflection.BindingFlags]::InvokeMethod,$null,$ie.document,'email')).value=$user
([System.__ComObject].InvokeMember('getElementById',[System.Reflection.BindingFlags]::InvokeMethod,$null,$ie.document,'Password')).value=$password
([System.__ComObject].InvokeMember('getElementById',[System.Reflection.BindingFlags]::InvokeMethod,$null,$ie.document,'Email')).focus()
[System.Windows.Forms.SendKeys]::SendWait(" {BS}")

([System.__ComObject].InvokeMember('getElementById',[System.Reflection.BindingFlags]::InvokeMethod,$null,$ie.document,'Password')).focus()
[System.Windows.Forms.SendKeys]::SendWait(" {BS}{Enter}")

exit

Open in new window

Got the attached.

Thanks,
Ben
Untitled.png
ASKER CERTIFIED SOLUTION
Avatar of rastoi
rastoi
Flag of Slovakia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bfuchs

ASKER

Thanks very much rastoi!
btw, I'm planning to have a few such requests in near future, will post a link here..
just wondering, are you also familiar with Access VBA?