Javascript 通过批处理文件自动登录到 Windows 7/Chrome 上的网站
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14204623/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Automatic login to a website on windows 7/Chrome via batch file
提问by Mowgli
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.
我有一个批处理文件。我有案例选择。如果用户键入 26,它将打开链接 1 chrome。如果用户键入 27,它将在 chrome 中打开链接 2。
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.
我在谷歌上寻找这样的脚本,但没有找到任何有用的东西。我知道一点 C++,unix,(还有一些 html 和 java 脚本)我不知道它是否可以在使用这些语言的 Windows 机器上完成,但即使可以完成,我认为与 VB 或C## 或其他一些高级语言。
I learned how to open multiple sites using basic windows batch commands enclosed in a bat file like:
我学会了如何使用包含在 bat 文件中的基本 Windows 批处理命令打开多个站点,例如:
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.
但是我仍然无法弄清楚实际上单击 bat 文件将如何帮助我登录网站,甚至无需输入用户名和密码。
Do I need to start learning VB(visual basic),dot net, or windows batch programming to do this.is this so dificult.. Please help.
我需要开始学习 VB(visual basic)、dot net 或 windows 批处理编程才能做到这一点。这太难了.. 请帮忙。
回答by Vishnu Prasad Kallummel
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 usernameinput box). Else you have to navigate to the right input box by using TAB.
该代码打开您的浏览器,等待页面加载,然后假设光标位于右侧输入框中(例如,在Gmail 中,它将位于用户名输入框中)输入用户名和密码。否则,您必须使用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.
如果您反对在脚本文件中写入密码,请将其保存在浏览器中并使用适当的 SendKeys 方法登录。
回答by Rahul
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))

