Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically open a browser and login to a site?

Tags:

batch-file

I have a 70 years old grandma that is not used to use the computer, but she has an e-mail and Facebook, and every time she wants to access those sites i have to help her through the process. So, i got an idea, i know a little of programing, so i tried to do a batch file to automatize this process of opening Firefox, typing "www.exemple.com", and login in her account. With this she could at least see if there are any emails or facebook notifications, but i could just do an batch to open the email site, i would like to know if there is any way to do a program to login. Batch File:

ECHO OFF
START FIREFOX "WWW.EXAMPLE.COM" "WWW.EXAMPLE2.COM"
EXIT
like image 400
André Monteiro Avatar asked Apr 02 '15 00:04

André Monteiro


2 Answers

Figured this out today, how one can use batch files on windows computers to push keyboard commands to websites or other applications if needed. See here for the original coding information.

The core of the command that you will find here simply results as

@if (@CodeSection == @Batch) @then


@echo off

rem Use %SendKeys% to send keys to the keyboard buffer
set SendKeys=CScript //nologo //E:JScript "%~F0"

%SendKeys% "{ENTER}"

goto :EOF


@end


// JScript section

var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));

While i myself am still experimenting and testing this batch file program on different applications, i am not sure as to the inner-workings of what this program actually does. All i know is it uses a java script installed on every windows computer to push keyboard commands to be executed. However in my experimentation i found that it could also serve as a means to fill in passwords and usernames.

@if (@CodeSection == @Batch) @then


@echo off

rem Use %SendKeys% to send keys to the keyboard buffer
set SendKeys=CScript //nologo //E:JScript "%~F0"
START FIREFOX "WWW.EXAMPLE.COM"
rem the script only works if the application in question is the active window. Set a timer to wait for it to load!
timeout /t 5
rem use the tab key to move the cursor to the login and password inputs. Most htmls interact nicely with the tab key being pressed to access quick links.
%SendKeys% "{TAB}"
rem now you can have it send the actual username/password to input box
%SendKeys% "{U}"
%SendKeys% "{s}"
%SendKeys% "{E}"
%SendKeys% "{r}"
%SendKeys% "{N}"
%SendKeys% "{a}"
%SendKeys% "{M}"
%SendKeys% "{e}"
%SendKeys% "{TAB}"
%SendKeys% "{P}"
%SendKeys% "{4}"
%SendKeys% "{S}"
%SendKeys% "{S}"
%SendKeys% "{W}"
%SendKeys% "{O}"
%SendKeys% "{R}"
%SendKeys% "{D}"
%SendKeys% "{ENTER}"

goto :EOF


@end
// JScript section

var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));

Thus logging your grandmother into the specific website. While this is a rough approximate of the code i would have attempted running, it should still work. If it doesn't, start from scratch with the link i provided. In addition, if you need ways to include those special characters check here as well.

*EDIT:

I later made something like this for myself and found a simpler way instead of typing out all those %SendKeys%. You can simply do

%SendKey% "Username{TAB}"
%SendKey% "Password{ENTER}"

as a more simpler way of going through the login process. The only downside to any of this is that if she decides to change her login, you would have to change her password from within the program.

like image 143
Jouster500 Avatar answered Nov 09 '22 02:11

Jouster500


This worked for me actually, I referred jouster500 answer, there were few bugs which I rectified, works like a charm.

@if (@CodeSection == @Batch) @then


@echo off

rem Use %SendKeys% to send keys to the keyboard buffer
set SendKeys=CScript //nologo //E:JScript "%~F0"
START CHROME "https://login.classy.org/"
rem the script only works if the application in question is the active window. Set a 
timer to wait for it to load!
timeout /t 10
rem use the tab key to move the cursor to the login and password inputs. Most htmls 
interact nicely with the tab key being pressed to access quick links.
rem %SendKeys% "{TAB}"
rem now you can have it send the actual username/password to input box
%SendKeys% "{TAB}"
%SendKeys% "{TAB}"
%SendKeys% "username"
%SendKeys% "{TAB}"
%SendKeys% "password"
%SendKeys% "{ENTER}"

goto :EOF

@end
// JScript section

var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));
like image 37
Varun Ved Avatar answered Nov 09 '22 02:11

Varun Ved