如何创建打开网站的批处理文件,例如gmail.com并输入用户名和密码

时间:2011-10-01 07:47:34

标签: batch-file

我需要创建一个打开网站(gmail)并输入用户名和密码的批处理文件。 所以任何人都可以帮助我.. 谢谢。

这是我试过的代码..它打开gmail,现在我怎样才能输入用户名和密码。

保存为Test.bat

@echo off
start /d "C:\Program Files\Internet Explorer" IEXPLORE.EXE https://gmail.com

7 个答案:

答案 0 :(得分:1)

不会让我评论,但我同意批处理是错误的方法。你可以用PowerShell做到这一点。

add-type -AssemblyName microsoft.VisualBasic
add-type -AssemblyName System.Windows.Forms
#Loads Website
C:\Progra~1\Intern~1\iexplore.exe -k http://www.gmail.com
#Enter Credentials
[System.Windows.Forms.SendKeys]::SendWait("userid{TAB}password{enter}")

答案 1 :(得分:0)

你不能这样做。您可以打开特定网址,但不能在表单中输入值。

您可以从命令提示符处打开电子邮件地址,但这将打开默认的电子邮件客户端,而不是某些Webmail页面。所以不幸的是,这是不可能的。

答案 2 :(得分:0)

我认为没有一种纯粹的方式来实现你的目标。

您可以尝试使用例如http://jsoup.org/来编写内容。但是,每当页面上出现新规范时,您都需要更改代码。

答案 3 :(得分:0)

这可以通过Selenium完成。您需要在Java中编写一个简单的Selenium JUnit测试。当然,这需要在计算机上安装Java。它将是大约20-30行代码。然后,您可以从批处理文件中执行JUnit测试,如下所示:

@ECHO off
SET username=me
SET password=mypassword
java -cp MyGmailTest.class MyGmailTest %username% %password%
timeout 10

答案 4 :(得分:0)

使用selenium的firefox WebDriver和java。

http://docs.seleniumhq.org/download/

导入所有必需的webDriver库,这将非常简单。像这样:

public class checkEmail{

public static void main(String args[]){
WebDriver driver = new FirefoxDriver();
driver.get("www.gmail.com");
driver.findElement(By.id("Email")).sendKeys("your usernamne");
driver.findElement(By.id("Passwd")).sendKeys("your password");
driver.findElement(By.id("signIn")).click();

}

}

获取.class文件,然后制作一个简单的批处理文件 @ECHO OFF set CLASSPATH= (wherever your selenium jars are) cd C:\where ever the class file is java checkEmail

答案 5 :(得分:0)

WITH FIREFOX:

@echo off

set command=C:\Users\%USERNAME%\Desktop\GMAIL.VBS

start https://gmail.com

echo Set objShell = WScript.CreateObject("WScript.Shell") > %command%

echo Set WshShell = WScript.CreateObject("WScript.Shell") >> %command%

echo Do Until Success = True >> %command%

echo     Success = objShell.AppActivate("Mozilla Firefox") >> %command%

echo Loop >> %command%

echo WshShell.SendKeys "USERNAME HERE" >> %command%

echo WshShell.SendKeys "{TAB}" >> %command%

echo WshShell.SendKeys "[PASSWORD HERE] >> %command%

echo WshShell.SendKeys "{ENTER}" >> %command%

ping 192.0.2.2 -n 1 -w 5000 > nul

start %command%

ping 192.0.2.2 -n 1 -w 1000 > nul

del %command%

exit
chance [USERNAME HERE] AND [PASSWORD] { with the [ ] }

使用GOOGLE CHROME

@echo off

set command=C:\Users\%USERNAME%\Desktop\GMAIL.VBS

start https://gmail.com

echo Set objShell = WScript.CreateObject("WScript.Shell") > %command%

echo Set WshShell = WScript.CreateObject("WScript.Shell") >> %command%

echo Do Until Success = True >> %command%

echo     Success = objShell.AppActivate("Google Chrome") >> %command%

echo Loop >> %command%

echo WshShell.SendKeys "USERNAME HERE" >> %command%

echo WshShell.SendKeys "{TAB}" >> %command%

echo WshShell.SendKeys "[PASSWORD HERE] >> %command%

echo WshShell.SendKeys "{ENTER}" >> %command%

ping 192.0.2.2 -n 1 -w 5000 > nul

start %command%

ping 192.0.2.2 -n 1 -w 1000 > nul

del %command%

exit
chance [USERNAME HERE] AND [PASSWORD] { with the [ ] } 

答案 6 :(得分:0)

@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% "username{TAB}"
%SendKeys% "password{ENTER}"

goto :EOF


@end
// JScript section

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

检查这个