Hello and thank you in advance for your time.
I am trying to automate a login for a specific site using VBscript. My code works great...up to a point. I execute the script, it opens IE, populates both the username and the password, and then submits. The problem is, after the credentials are submitted, I get an error saying the username and/or password is incorrect. I know 100% both the username and password are in fact correct.
I am quite sure I have located the culprit, however I cannot figure out how I should amend my code to accommodate. A good look at the login screen with firebug revealed a domain was being appended to the username. My code does not reflect this, therefore I get the username/password error after I submit.
Here is my code... and below my code is the JavaScript pulled from the website using firebug:
On Error Resume Next
Const PAGE_LOADED = 4
Set objIE = CreateObject("InternetExplorer.Application")
Call objIE.Navigate("https://snvacaid-bwxsp01.megapathvoice.com/Login/")
objIE.Visible = True
Do Until objIE.ReadyState = PAGE_LOADED : Call WScript.Sleep(100) :
Loop
objIE.Document.loginForm.EnteredUserID.Value = "username"
objIE.Document.all.Password.Value = "password"
If Err.Number <> 0 Then
msgbox "Error: " & err.Description
End If
Call objIE.Document.all.loginForm.submit
Set objIE = Nothing
JavaScript from website:
function submitForm() {
//append domain to the userId if it is available and not
//already contained in the userId
var userId = document.loginForm.EnteredUserID.value;
var domain = document.loginForm.domain.value;
document.loginForm.UserID.value = userId;
if ((userId.indexOf("#") == -1) && (domain != "")){
document.loginForm.UserID.value = userId + "#" + domain;
}
document.loginForm.submit();
}
Sorry for taking so long in informing all that I answered my own question; however, below is the solution I came up with and it does work. Thank you for all the replies.
On Error Resume Next
Const PAGE_LOADED = 4
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objIE = CreateObject("InternetExplorer.Application")
Call objIE.Navigate("https://snvacaid-bwxsp01.megapathvoice.com/Login/")
objIE.Visible = True
Do Until objIE.ReadyState = PAGE_LOADED : Call WScript.Sleep (100)
Loop
objIE.Document.loginForm.UserID.Value = "username"
objIE.Document.all.Password.Value = "password"
If Err.Number <> 0 Then
msgbox "Error: " & err.Description
End If
Call objIE.Document.all.loginForm.submit
Related
I am writing a VB script to automatically mount a network drive for a network location hosted by our Synology NAS DS218j device (if that's important) at each computer start-up. I also want users to enter their username and password if they are prompted by the NAS device. The problem is, that the NAS user profiles may differ from those for Windows 10, so each user has to enter its username and password when connecting to the NAS device location (also while mounting network drives) for the first time:
After the first successful log in the credentials can be saved.
The problems is:
How to get to this prompt window from VBScript? What I tried to do already is:
Simply to mount the drive: I get an error, that the username and password are invalid (clear, because it uses the windows profile password):
Dim objNetwork
Set objNetwork = CreateObject("WScript.Network")
strDriveLetter = "T:"
strRemotePath = "\\192.168.2.247\BlaBla"
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath
To catch the error and tell the explorer to open the window (to imitate the behaviour, what user does manually to get the NAS login window open):
If Err.Number <> 0 Then
WScript.Echo CStr(Err.Description)
If Err.Number = CLng("&H" & 80070056) Then
On Error Goto 0
Dim objShell
Set objShell = CreateObject("WScript.Shell")
Dim intReturn
Dim cmdString
cmdString = "Explorer.exe /n,/root," + strRemotePath
intReturn = objShell.Run(cmdString, 1, True)
Else
WScript.Quit
End If
End If
What that actually does is opening the "Documents" folder! It also does not wait for the window to get closed (what I actually expected to be done, by giving the third argument True to objShell.Run command.
I have considered a solution through the IE-based custom dialogbox to prompt users for their passwords, but the problem with thit approach is, that in this case, users have to enter their username and password each time they start/restart his/her PC (no save option). The Dialog, which Windows presents, allows the users to save their password for the next time.
Saving user passwords, which I collect from that custom dialog-box is not the solution I am seeking for, because then I have the security issue.
Any ideas how to get to this login window through VBScript commands?
Do not try to automate the password dialog Windows is presenting you with. Instead pass the credentials via the respective parameters of the MapNetworkDrive method:
username = "..."
password = "..."
...
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, False, username, password
If you need to prompt the user for their credentials (that wasn't clear to me from your question) the simplest way would be using InputBox dialogs. However, since you can't hide the password input in those you may want to create a custom dialog instead. Something like this:
Set ie = CreateObject("InternetExplorer.Application")
ie.Navigate "about:blank"
ie.Document.title = "Title"
ie.ToolBar = False
ie.Resizable = False
ie.StatusBar = False
ie.Width = 320
ie.Height = 180
While ie.ReadyState <> 4 : WScript.Sleep 100 : Wend
ie.Document.body.innerHTML = _
"<p><input type='text' size='20' id='Username'></p>" & vbNewLine & _
"<p><input type='password' size='20' id='Password'></p>" & vbNewLine & _
"<p><input type='hidden' id='OK' name='OK' value='0'>" & _
"<input type='submit' value='Foo' onClick='VBScript:OK.value=1'></p>"
ie.Document.body.style.overflow = "auto"
ie.Visible = True
ie.Document.all.Username.focus
On Error Resume Next
Do While ie.Document.all.OK.value = 0
WScript.Sleep 100
Loop
On Error Goto 0
username = objIE.Document.all.Username.value
password = objIE.Document.all.Password.value
On Error Resume Next:
Const PAGE_LOADED = 4
Set objIE = CreateObject("InternetExplorer.Application")
Call objIE.Navigate("http://172.25.25.32:8090/")
objIE.Visible = True
Do Until objIE.ReadyState = PAGE_LOADED : Call WScript.Sleep(100) : Loop
objIE.Document.all.Username.Value = "ashishgi"
objIE.Document.all.Password.Value = "apac2015#"
If Err.Number <> 0 Then
msgbox "Error: " & err.Description
End If
Call objIE.Document.all.gaia_loginform.submit
Set objIE = Nothing
The gaia_loginform is the "form id" of Gmail. Have a look here: http://i.imgur.com/45H7pKP.jpg.
Now I think you should get the form name/id of the site (by viewing the source) so that the script can hit the login button.
I am using below VB script for auto login in to website. It is entering username but it does not enter password and gives the error that 'doesn't support this property or method' . I have not worked in VB script , so not sure why this error is coming.
On Error Resume Next
Const PAGE_LOADED = 4
Set objIE = CreateObject("InternetExplorer.Application")
Call objIE.Navigate("http://www.gmail.com")
objIE.Visible = True
Do Until objIE.ReadyState = PAGE_LOADED : Call WScript.Sleep(100) : Loop
objIE.Document.all.username.Value = "username"
objIE.Document.all.Passwd.Value = "password"
If Err.Number <> 0 Then
msgbox "Error: " & err.Description
End If
Call objIE.Document.all.login_form.submit
Set objIE = Nothing
Try if this code can did the trick or not because gmail has changed its source code !
Dim IE
Set IE = Wscript.CreateObject("InternetExplorer.Application")
IE.Visible = 1
IE.navigate("https://accounts.google.com/ServiceLogin?service=ig&passive=true&continue=http://www.google.com/ig%3Fhl%3Den&followup=http://www.google.com/ig%3Fhl%3Den&cd=US&hl=en&nui=1<mpl=default")
Do While (IE.Busy)
WScript.Sleep 10
Loop
Set Helem = IE.document.getElementById("Email")
Helem.Value = "Your Login goes here" 'Change to your Gmail login
Set Helem = IE.document.Forms(0)
Helem.Submit
Do While (IE.Busy)
WScript.Sleep 10
Loop
wscript.sleep 2000
Set Helem = IE.document.getElementById("Passwd")
Helem.Value = "Your Password goes here" 'Change to your Gmail password
Set Helem = IE.document.Forms(0)
Helem.Submit
I'm writing a VBScript that will simply check each user in AD if their password has been changed within a given number of days. When I was trying to get it working for a single user, I came up with the following working code:
Option Explicit
Dim objUser, strLDAPConnection, intPwdExpLimit
strLDAPConnection = "CN=Test User,OU=Test,OU=Employees,DC=domain,DC=com"
intPwdExpLimit = 90
Set objUser = GetObject("LDAP://" + strLDAPConnection)
WScript.Echo DaysSincePwdChange(objUser)
Function DaysSincePwdChange(objUserAccount)
DaysSincePwdChange = dateDiff("d", objUserAccount.PasswordLastChanged, Now)
End Function
So then I tried to get it to work by looping through all users in a Test OU with the following code:
Option Explicit
Const strOffice = "Test"
Dim objEmployeesOU, objUser, intPwdExpLimit
intPwdExpLimit = 90
Set objEmployeesOU = GetObject("LDAP://OU=" & strOffice & _
",OU=Employees,DC=domain,DC=com")
For Each objUser In objEmployeesOU
If objUser.class = "user" Then
If ((DaysSincePwdChange(objUser)) >= intPwdExpLimit) Then
MsgBox(objUser & ": Password Expired.")
Else
MsgBox(objUser & ": Password Current.")
End If
End If
Next
Function DaysSincePwdChange(objUserAccount)
DaysSincePwdChange = dateDiff("d", objUserAccount.PasswordLastChanged, Now)
End Function
The above code produces a 0x8000500D error and googling the error says that it can't find the property in the cache (referring to the PasswordLastSet property, see error description link here).
Any ideas why the first block of code works fine but the second has a problem accessing that property?
Error code 0x8000500d means E_ADS_PROPERTY_NOT_FOUND. The password of the user has never been changed, so the property is not set. You could handle the condition like this:
Function DaysSincePwdChange(objUserAccount)
On Error Resume Next
DaysSincePwdChange = dateDiff("d", objUserAccount.PasswordLastChanged, Now)
If Err Then
If Err.Number = &h8000500d Then
DaysSincePwdChange = -1
Else
WScript.Echo "Unexpected Error (0x" & Hex(Err.Number) & "): " & _
Err.Description
WScript.Quit 1
End If
End If
End Function
and modify the check like this:
passwordAge = DaysSincePwdChange(objUser)
If passwordAge >= intPwdExpLimit) Then
MsgBox(objUser & ": Password Expired.")
ElseIf passwordAge = -1 Then
MsgBox(objUser & ": Password never changed.")
Else
MsgBox(objUser & ": Password Current.")
End If
I've got the vbscript below which needs to send a GET request and then logoff the current user. The idea is to replace the default "logoff" start menu item with this script.
When I run it with cscript it throws an error on line 9,
HTTPGet = IE.document.documentelement.outerhtml
I don't understand what's wrong. Maybe I should wait to receive the response before logging off the user, but as the line above doesn't seem to work I logoff immediately.
TOKEN = "xxxxx"
Set IE = CreateObject("InternetExplorer.Application")
IE.visible = 0
IE.navigate "https://something.com/?action=create&token=" & TOKEN
Do While IE.Busy
WScript.Sleep 200 ' see the above notice of change
Exit Do ' prevents script host from going crazy waiting for IE
loop
HTTPGet = IE.document.documentelement.outerhtml
IE.quit
Set IE = Nothing
'WScript.Echo HTTPGet 'good for debugging. shows what you got back.
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "C:\WINDOWS\system32\shutdown.exe -l"
If it matters this is for Windows XP only with IE 8.
Try out this code:
Set IE = CreateObject("InternetExplorer.Application")
IE.visible = 0
IE.navigate "https://host/?a=" & TOKEN
i = 1
Do While (IE.readyState <> 4)
WScript.Sleep 1000 ' see the above notice of change
i = i + 1
If (i > 10) Then
Exit Do
End If
loop
HTTPGet = IE.document.documentElement.outerHTML
IE.Quit()
Set IE = Nothing