Set objPassword = CreateObject("ScriptPW.Password")
WScript.StdOut.Write "Please enter your password:"
strPassword = objPassword.GetPassword()
Wscript.Echo
Wscript.Echo "Your password is: " & strPassword
strPassword = objPassword.GetPassword()
'=======================[ ASK Password ]========================================'
Option Explicit
Dim strUserID, strPassword
AskPassword
Sub AskPassword()
Dim htmlPwdCode, objCodeFile, objFileSysObj, objBrowser, strButton
Const FOR_WRITING = 2
Set objFileSysObj = CreateObject("Scripting.FileSystemObject")
htmlPwdCode = "<SCRIPT LANGUAGE=" & Chr(34) & "VBScript" & Chr(34) & ">" & Chr(13) & _
"Sub RunScript" & Chr(13) & _
" OKClicked.Value = " & Chr(34) & "OK"& Chr(34) & Chr(13) & _
"End Sub" & Chr(13) & _
"Sub CancelScript" & Chr(13) & _
" OKClicked.Value = " & Chr(34) & "Cancelled" & Chr(34) & Chr(13) & _
"End Sub" & Chr(13) & _
"Sub Default_Buttons" & Chr(13) & _
" If Window.Event.KeyCode = 13 Then" & Chr(13) & _
" btnOK.Click" & Chr(13) & _
" End If" & Chr(13) & _
"End Sub" & Chr(13) & _
"</SCRIPT>" & Chr(13) & _
"<BODY onkeypress='vbs:Default_Buttons'><center><font size=" & Chr(34) & "2" & Chr(34) & " face=" & Chr(34) & "Arial" & Chr(34) & ">" & Chr(13) & _
"User name: " & Chr(13) & _
"<input type=" & Chr(34) & "text" & Chr(34) & " name=" & Chr(34) & "UserName" & Chr(34) & " size=" & Chr(34) & "30" & Chr(34) & "><br>" & Chr(13) & _
"Password : </font><font face=" & Chr(34) & "Arial" & Chr(34) & ">" & Chr(13) & _
"<input type=" & Chr(34) & "password" & Chr(34) & " name=" & Chr(34) & "UserPassword" & Chr(34) & _
" size=" & Chr(34) & "30" & Chr(34) & "></font></p>" & Chr(13) & _
"<input type=" & Chr(34) & "hidden" & Chr(34) & " name=" & Chr(34) & "OKClicked" & Chr(34) & " size = " & Chr(34) & "20" & Chr(34) & ">" & Chr(13) & _
"<input id=" & Chr(34) & "btnOK" & Chr(34) & " class=" & Chr(34) & "button" & Chr(34) & _
" type=" & Chr(34) & "button" & Chr(34) & " value=" & Chr(34) & " OK " & Chr(34) & _
" name=" & Chr(34) & "ok_button" & Chr(34) & " onClick=" & Chr(34) & "RunScript" & Chr(34) & ">" & Chr(13) & _
"<input id=" & Chr(34) & "btnCancel" & Chr(34) & " class=" & Chr(34) & "button" & Chr(34) & _
" type=" & Chr(34) & "button" & Chr(34) & " value=" & Chr(34) & "Cancel" & Chr(34) & _
" name=" & Chr(34) & "cancel_button" & Chr(34) & " onClick=" & Chr(34) & "CancelScript" & Chr(34) & "></center></BODY>"
Set objCodeFile = objFileSysObj.CreateTextFile("AskPassword.html", True)
objCodeFile.Write htmlPwdCode
objCodeFile.Close
Set objCodeFile = Nothing
Set objBrowser = CreateObject("InternetExplorer.Application")
With objBrowser
.Height = 170
.Width = 400
.Top = 200
.Left = 300
.StatusBar = True
.Toolbar = False
.Resizable = False
.Navigate CreateObject("Scripting.FileSystemObject").GetParentFolderName(Wscript.ScriptFullName) & "\AskPassword.html"
.Visible = True
End With
Do Until objBrowser.ReadyState = 4
'wait till page loads'
Loop
Do While objBrowser.Document.Body.All.OKClicked.Value = ""
Wscript.Sleep 50
Loop
strUserID = objBrowser.Document.Body.All.UserName.Value
strPassword = objBrowser.Document.Body.All.UserPassword.Value
strButton = objBrowser.Document.Body.All.OKClicked.Value
objBrowser.Quit
If strButton = "Cancelled" Then
MsgBox "Operation cancelled, script will now exit!"
Wscript.Quit
Else
'Credentials accepted for further processing
End If
objFileSysObj.DeleteFile "AskPassword.html", True
Set objBrowser = Nothing
Set objFileSysObj = Nothing
End Sub
'=======================[ GOT Password ]========================================'
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (6)
Commented:
Commented:
Commented:
So it did. Thanks aikimark. Fixed.
Sungenwang, it should work from the root of a drive if you change this:
.Navigate CreateObject("Scripting.Fi
to this
.Navigate Replace(CreateObject("Scri
Regards,
Rob.
Commented:
Commented:
I am trying to use this script but when the browser window opens, the script exits.
'The interface is unknown' at line 59
Do Until objBrowser.ReadyState = 4
Can anyone help?
View More