2011-10-01 114 views
1

我需要創建一個批處理文件,該文件打開一個網站(gmail)並輸入用戶名和密碼。 所以任何人都可以幫助我.. 謝謝。如何創建打開網站的批處理文件例如gmail.com並輸入用戶名和密碼

這裏是我試過的代碼..它打開gmail,現在我怎麼輸入用戶名和密碼。

保存爲TEST.BAT

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

批處理文件是不是這個合適的工具。 – Mat

回答

0

你不能做到這一點。您可以打開特定的網址,但無法在表單中輸入值。

您可以從命令提示符打開電子郵件地址,但這將打開默認的電子郵件客戶端,而不是某個Webmail頁面。所以很不幸,這是不可能的。

+0

@niths你的問題解決了嗎? – GolezTrol

0

我不認爲有一個純粹的批量方式來實現你的目標。

您可以嘗試寫一些東西,例如使用http://jsoup.org/。但是,每當網頁上有新的規範時,您都需要更改代碼。

0

這可以用硒來完成。你需要用Java編寫一個簡單的Selenium JUnit測試。當然,這要求將Java安裝在計算機上。這將是大約20-30行代碼。然後,你可以像批處理文件那樣執行JUnit測試:

@ECHO off 
SET username=me 
SET password=mypassword 
java -cp MyGmailTest.class MyGmailTest %username% %password% 
timeout 10 
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

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}") 
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 [ ] } 

與谷歌瀏覽

@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 [ ] } 
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)); 

檢查這個

相關問題