some times we need to prompt input box for a password and we need to hide a password while it is being typed.
But it is not possible with normal VBScript . we can use the AOM for IE with VBScript to do this.
Following is the code
strPw = GetPassword( “Please enter your password:” )
msgbox “Your password is: ” & strPw
Function GetPassword( myPrompt )
‘ This function uses Internet Explorer to
‘ create a dialog and prompt for a password.
Dim objIE
‘ Create an IE object
Set objIE = CreateObject( “InternetExplorer.Application” )
‘ specify the IE settings
objIE.Navigate “about:blank”
objIE.Document.Title = “Password”
objIE.ToolBar = False
objIE.Resizable = False
objIE.StatusBar = False
objIE.Width = 300
objIE.Height = 180
‘ Center the dialog window on the screen
With objIE.Document.ParentWindow.Screen
objIE.Left = (.AvailWidth – objIE.Width ) \ 2
objIE.Top = (.Availheight – objIE.Height) \ 2
End With
‘ Insert the HTML code to prompt for a password
objIE.Document.Body.InnerHTML = “<DIV align=”"center”"><P>” & myPrompt _
& “</P>” & vbCrLf _
& “<P><INPUT TYPE=”"password”" SIZE=”"20″” ” _
& “ID=”"Password”"></P>” & vbCrLf _
& “<P><INPUT TYPE=”"hidden”" ID=”"OK”" ” _
& “NAME=”"OK”" VALUE=”"0″”>” _
& “<INPUT TYPE=”"submit”" VALUE=”" OK “” ” _
& “OnClick=”"VBScript:OK.Value=1″”></P></DIV>”
‘ Make the window visible
objIE.Visible = True
‘ Wait till the OK button has been clicked
Do While objIE.Document.All.OK.Value = 0
WScript.Sleep 200
Loop
‘ Read the password from the dialog window
GetPassword = objIE.Document.All.Password.Value
‘ Close and release the object
objIE.Quit
Set objIE = Nothing
End Function
The code will create the screen like this

Author: Robvan der Woude
February 15, 2008 -
Posted by
quicktestprofessional |
VBScript and IE Automation |
hide a password, hide a password while it is being typed, QTP, VBScript |
5 Comments
Another thing i would like to ask you that “Do you have some idea about how to use QTP on mainframes? I am a project manager here on a mainframe project and we are planing to get do automation using QTP. I will greatly appriciate your help
Pari,
You have to use TE(Terminal Emulator)Addin for that.You have to buy that seperatly.
When I am using IE.Visible = TRUE, Application displays for a sec and disapperas,Is there ay method to display the form
Very usefull. Thank you for taking the time to share.
-O
Dear,
I have this below password. it is working good. but the problem is when it ask for password and when i type password the text show in the box is visible. it should come in “******” form. just guide me how can i edit this code to get password like this.
thanks
Private Sub CommandButton2_Click()
If MsgBox(“Are you sure(You have to enter a correct password otherwise this workbook will be closed) ?”, vbYesNo + vbQuestion) = vbNo Then
Exit Sub
Else
‘Code goes here
Dim pass As String
pass = InputBox(“Enter Password”)
If pass “sulaiman” Then ThisWorkbook.Close Saved = True
Unload Me
End If
End Sub