2013-10-10 340 views
0

我嘗試創建一個VBS腳本,自動啓動了一個網站。這部分我可以解決。 但現在我需要把這個腳本的功能登錄爲 這就是我呆呆的點。登錄網站登錄名和密碼

所以我希望你能幫助我。 這裏是我拿開的網站

Dim objExplorer 


Set objExplorer = WScript.CreateObject("InternetExplorer.Application") 

Do While (objExplorer.Busy) 
Wscript.Sleep 250 
Loop 

objExplorer.TheaterMode = False 
objExplorer.AddressBar = True 
objExplorer.MenuBar = True 
objExplorer.StatusBar = True 
objExplorer.ToolBar = False 
objExplorer.Resizable = True 


objExplorer.Height = 600 
objExplorer.Width = 800 
objExplorer.Left = 0 
objExplorer.Top = 0 
' objExplorer.FullScreen = True 
objExplorer.Silent = False 
objExplorer.Visible = True 


objExplorer.Navigate https://mi-xxxxx-xxx-xxxxx.xxx.com/xxxxxxxxxxxxx/login.aspx 

objExplorer.Login = User 
ObjExplorer.Password = Password 

wscript.sleep 6000 

Set objShell = CreateObject("Wscript.Shell") 
objShell.Run("taskkill /F /IM iexplore.exe /T") 

Set objExplorer = nothing 

我希望有一個簡單的方法來一個結果腳本。

非常感謝您的幫助。 最好的問候 馬丁

回答

2

而不是嘗試通過GUI自動化登錄嘗試檢查登錄過程像Fiddler。這應該會給你提供將客戶端證書傳遞給服務器的實際請求。有了這些信息,你可以使用XMLHttpRequest自動登錄:

url = "https://mi-xxxxx-xxx-xxxxx.xxx.com/xxxxxxxxxxxxx/login.asp" 

user = "..." 
pass = "..." 
credentials = "username=" & user & "&password=" & pass 

Set req = CreateObject("Msxml2.XMLHttp.6.0") 
req.open "POST", url, False 
req.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" 
req.send credentials 

If req.status = 200 Then 
    'login successful 
Else 
    'login failed 
End If 

您可能需要根據什麼提琴手透露調整urlcredentials字符串。你可能還需要用這樣的東西來編碼用戶名和/或密碼:

Function Encode(ByVal str) 
    Set re = New RegExp 
    re.Pattern = "[^a-zA-Z0-9_.~-]" 

    enc = "" 
    For i = 1 To Len(str) 
    c = Mid(str, i, 1) 
    If re.Test(c) Then c = "%" & Right("0" & Hex(Asc(c)), 2) 
    enc = enc & c 
    Next 

    Encode = enc 
End Function 
+0

這是一個很好的建議。你知道任何不需要軟件安裝的選擇嗎?我處於禁止軟件安裝的工作環境中,但我們仍然可以運行可執行文件。我很樂意將它融入到我現有的一些腳本中。 –

+0

@BHart號您需要SSL代理來分解SSL連接才能檢查HTTPS請求。我認爲沒有管理員權限就可以設置這樣的東西。 –

+0

數字:P感謝您的及時響應! –

0

我發現一個很好的方式來需要結果。

WScript.Sleep 5000 
WshShell.SendKeys "******" 
WScript.Sleep 3000 
WshShell.SendKeys "{TAB}" 
WScript.Sleep 3000 
WshShell.SendKeys "*********" 
WshShell.SendKeys "{TAB}" 
WScript.Sleep 3000 
WshShell.SendKeys "{ENTER}" 

wscript.sleep 10000 

所以這個任務就解決了。 非常感謝您的所有命令。 最好問候 馬丁