Rob van der Woude's Scripting Pages

VBScript Scripting Techniques > User Interaction > Login

Login Dialog

 

InternetExplorer.Application
VBScript Code:
Function IELogin( )
' This function uses Internet Explorer to create a login dialog.
'
' Version:             3.11
' Last modified:       2013-11-07
'
' Arguments:           N/A
' Returns:    [array]  the user name (0) and password (1)
'                      typed in the dialog screen
'
' Written by Rob van der Woude
' http://www.robvanderwoude.com
' Error handling code written by Denis St-Pierre

    Dim objIE
    ' Create an IE object
    Set objIE = CreateObject( "InternetExplorer.Application" )
    ' specify some of the IE window's settings
    objIE.Navigate "about:blank"
    objIE.Document.title = "Login" & String( 80, "." )
    objIE.ToolBar        = False
    objIE.Resizable      = False
    objIE.StatusBar      = False
    objIE.Width          = 320
    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
    ' Wait till IE is ready
    Do While objIE.Busy
        WScript.Sleep 200
    Loop
    ' Insert the HTML code to prompt for user input
    objIE.Document.body.innerHTML = "<div align=""center"">" & vbcrlf _
                                  & "<table cellspacing=""5""><tr nowrap>" _
                                  & "<td>Name:</td><td>" _
                                  & "<input type=""text"" size=""20"" " _
                                  & "autocomplete=""off"" " _
                                  & "id=""LoginName""></td></tr>" & vbcrlf _
                                  & "<tr nowrap><td>Password:</td>" _
                                  & "<td><input type=""password"" size=""20"" " _
                                  & "id=""Password""></td>" & vbcrlf _
                                  & "</tr></table>" & vbcrlf _
                                  & "<p><input type=""hidden"" id=""OK"" " _
                                  & "name=""OK"" value=""0"">" _
                                  & "<input type=""submit"" value="" OK "" " _
                                  & "onClick=""VBScript:OK.value=1""></p></div>"
    ' Hide the scrollbars
    objIE.Document.body.style.overflow = "auto"
    ' Make the window visible
    objIE.Visible = True
    ' Set focus on input field
    objIE.Document.all.LoginName.focus

    ' Wait till the OK button has been clicked
    On Error Resume Next
    Do While objIE.Document.all.OK.value = 0
        WScript.Sleep 200
        If Err Then    'user clicked red X (or alt-F4) to close IE window
            IELogin = Array( "", "" )
            objIE.Quit
            Set objIE = Nothing
            Exit Function
        End if
    Loop
    On Error Goto 0
    
    
    ' Read the user input from the dialog window
    IELogin = Array( objIE.Document.all.LoginName.value, objIE.Document.all.Password.value )
    ' Close and release the object
    objIE.Quit
    Set objIE = Nothing
End Function
 
Internet Explorer login dialog
 
Requirements:
Windows version: any
Network: any
Client software: Internet Explorer 4 or later
Script Engine: WSH (CSCRIPT and WSCRIPT)
(to use in HTAs, remove both WScript.Sleep lines)
Summarized: Works in all Windows versions with Internet Explorer 4 or later, remove both WScript.Sleep lines to use in HTAs.
 
[Back to the top of this page]

page last uploaded: 2016-09-19, 14:58