9

I have a batch file. I have case select. if user types 26 it will open link 1 chrome. if user types 27 it will open link 2 in chrome.

But I still can't figure out, how can I make batch login automatically into website with username and password.

I looked for such a script on the google but didn't find anything useful. I know a bit of C++, unix,(also some html and java script) I don't know if it can be done on windows machine using these languages but even if it could be done I think it would be difficult compared to VB or C## or some other high level languages.

I learned how to open multiple sites using basic windows batch commands enclosed in a bat file like:

start chrome.exe http://yahoo.com
start chrome.exe http://www.google.tv

But still I can't figure out how would actually a click on the bat file would help me to login to the sites also without even typing the username and password.

Do I need to start learning VB(visual basic),dot net, or windows batch programming to do this.is this so dificult.. Please help.

10
  • 1
    Have your login page set a token in cookies upon first login. Have your login script look for that token and and authenticate accordingly.
    – Bryan Allo
    Jan 7, 2013 at 21:50
  • 1
    Unless you're trying to authenticate with windows user credentials, say via an LDAP integration, I would just use a token in a cookie with a long life. It won't matter then what browser you use or your batch file calls. You login script can handle that. This way you can also revoke security tokens as needed and security/access is more centralized and manageable.
    – Bryan Allo
    Jan 7, 2013 at 21:52
  • Thanks for hint guys, I am new to cookies and token can you please provide me with some link or guide where I can read more and proceed from there. Thanks
    – Mowgli
    Jan 7, 2013 at 21:56
  • The approach I suggested assumes you have access to the login script/functions. This this correct?
    – Bryan Allo
    Jan 7, 2013 at 21:57
  • No, I just wrote batch code for user(mom and dad) to type in (channel number) and it will open tv stream link in web browser, if it doesn't need login (if it is already logged in) it will automatically full screen the stream via autohotkey script which I also wrote.
    – Mowgli
    Jan 7, 2013 at 22:00

2 Answers 2

14

You can try the following code:

set WshShell = WScript.CreateObject("WScript.Shell")
call WshShell.Run("http://www.gmail.com", 1, false) 'This will open your default browser

WScript.Sleep 2000
WshShell.SendKeys "username"
WScript.Sleep 1000
WshShell.SendKeys "{TAB}"
WScript.Sleep 1000
WshShell.SendKeys "password"
WshShell.SendKeys "{TAB}"
WScript.Sleep 1000
WshShell.SendKeys "{ENTER}"
WScript.Quit()

The code opens your browser, waits for the page to load, and then enters the username and password assuming that the cursor is in the right input box (for example, in Gmail, it will be on the username input box). Else you have to navigate to the right input box by using TAB.

If you are against writing the password in the script file, save it on you browser and use the appropriate SendKeys method for logging in.

-2

i tried above script for my website, but only able to see login page not able to put user name and password, need help

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


@echo off

set SendKeys=CScript //nologo //C:JScript "%~F0"
START iexplore.exe "www.gmail.com"
timeout /t 5
%SendKey% "USERNAME{TAB}"
%SendKey% "PASSWORD{Continue}"

goto :EOF


@end
// JScript section

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.