Logon to website the Login and password

2019-09-06 10:11发布

I try to create a VBS script, what started automatically an website. This part could I solve. But now I need to put in this script the function login as And that is the point i stay stucked.

So I hope you can help me. Here is the script I take to open the website

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

I hope there is a easy way to come to an result.

Many thanks for your Help in this case. best Regards Martin

标签: vbscript
2条回答
我只想做你的唯一
2楼-- · 2019-09-06 10:36

I find an great way to come to need result.

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

So this task is solved. many thanks for all your commands. best Regards martin

查看更多
姐就是有狂的资本
3楼-- · 2019-09-06 10:54

Instead of trying to automate the login via the GUI try inspecting the login process with something like Fiddler. That should give you the actual request that's passing the credentials from the client to the server. With that information you can use an XMLHttpRequest to automate the login:

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

You may need to adjust the url and credentials strings according to what Fiddler revealed. You may also need to encode username and/or password with something like this:

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
查看更多
登录 后发表回答