0

I'm currently opening a local url from batch command (.bat file) like this:

@echo off
start /d "C:\Program Files\Internet Explorer" IEXPLORE.EXE http://some_local_address:88

This is working fine.
The first thing that this site does is to ask for a username and password in a popup window. Is it possible to pass this information (or at least username) from the .bat file itself, so it is auto-completed in the emerging login window?

(Note that I'm aware you can complete username and password the first time, and "remember credentials", I just want to know if this is possible to pass from command line and how).

7
  • 1
    The only way I know of is to pass it through the URL (e.g. user:[email protected]) if the site uses basic auth, but this is disabled by default in newer versions of IE/edge. Beyond that I think you're in saved password / add-on territory
    – BrianC
    Commented Mar 16, 2016 at 0:05
  • If you can get your batch file to send keystrokes I don't see why not. Depending on how the page is setup I would imagine you could open the page, send Tab until the cursor is in the username box, send the username, send Tab again, send the password, send Enter.
    – root
    Commented Mar 16, 2016 at 16:18
  • You may be able to use curl.exe, which allows certain fields to be set. Otherwise, there is the Selenium add-on for Firefox, but you won't easily be able to control this from a batch file.
    – AFH
    Commented Mar 16, 2016 at 18:53
  • @BrianC, that is no longer supported.
    – zed
    Commented Mar 17, 2016 at 14:09
  • @root, any example on how to do that?
    – zed
    Commented Mar 17, 2016 at 14:11

2 Answers 2

1

I don't think this can be done using a batch file as batch has its own limitations, instead you can you the below VB script.

Set IE = CreateObject("InternetExplorer.Application")
IE.navigate "http://TheWebsite"
IE.Visible = True`

While IE.Busy
    WScript.Sleep 50
Wend

Set ipf = IE.document.all.username
ipf.Value = "Username" 
Set ipf = IE.document.all.password
ipf.Value = "Password" 
Set ipf = IE.document.all.Submit
ipf.Click 
IE.Quit

Update Website name, uname and passwd and then save this as AutoWebsite.vbs

5
  • Thank you. This does not work since the login is not an html form, but a windows prompt instead, which opens up when you hit the website.
    – zed
    Commented Mar 17, 2016 at 13:58
  • I don't understand windows prompt.
    – manjesh23
    Commented Mar 17, 2016 at 15:00
  • Sorry, I mean that the login is a little window that pops up asking for username and password, which is not an html form but a browser window instead.
    – zed
    Commented Mar 17, 2016 at 15:09
  • Use curl: stackoverflow.com/questions/2594880/…
    – pbies
    Commented Jul 17, 2017 at 18:22
  • I used this but i am unable to login.
    – Myanju
    Commented Feb 9, 2018 at 11:25
0

Hope this will help.

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

rem wait for the browser to finish loading
timeout /t 10

%SendKeys% "your_username"
%SendKeys% "{TAB}"
%SendKeys% "your_password"
%SendKeys% "{ENTER}"

goto:EOF

@end
// JScript section

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

thanks to @Varun_ved

source:https://stackoverflow.com/questions/29403376/automatically-open-a-browser-and-login-to-a-site

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .