(view source code of ielogin.vbs as plain text)
Option ExplicitDim arrLogin, strNamestrName = NullIf WScript.Arguments.Unnamed.Count = 1 Then strName = WScript.Arguments.Unnamed(0)
arrLogin = IELogin( strName )
WScript.Echo arrLogin(0) & vbTab & arrLogin(1)
Function IELogin( myName )
' This function uses Internet Explorer to create a login dialog.'' Script Name: IELogin.vbs' Version: 4.00' Last modified: 2016-12-22'' Arguments: [string] optional user name (use "" or Null to leave user name field blank)' Returns: [array] the user name (0) and password (1) typed in the dialog screen'' The output of IELogin.vbs is meant to be used in a batch file, using the following' batch code or something similar (note: the white space following delims= is a tab):'' REM * * * start of batch code * * *'' FOR /F "tokens=1,2 delims= " %%A IN ('CSCRIPT //NoLogo IELogin.vbs') DO (' SET Name=%%~A' SET Password=%%~B' )' ECHO The password of %Name% is %Password%'' REM * * * end of batch code * * *'' Written by Rob van der Woude' http://www.robvanderwoude.com' Error handling code written by Denis St-Pierre Dim intScreenHeight, intScreenWidth Dim colItems, objIE, objItem, objWMIService, wshShell Dim strHTML, strDialogTitle, strName 'On Error Resume NextstrName = Trim( " " & myName )
' Create an IE objectSet objIE = CreateObject( "InternetExplorer.Application" )
' specify some of the IE window's settingsobjIE.Navigate "about:blank"
strDialogTitle = "Login" & String( 80, Chr( 8 ) )
objIE.Document.Title = strDialogTitle
objIE.ToolBar = False
objIE.Resizable = False
objIE.StatusBar = False
objIE.Width = 320
objIE.Height = 180
' Wait till IE is readyDo While objIE.Busy
WScript.Sleep 200
Loop ' Center the dialog window on the screenSet objWMIService = GetObject( "winmgmts://./root/CIMV2" )
Set colItems = objWMIService.ExecQuery( "SELECT * FROM Win32_DesktopMonitor" )
For Each objItem in colItems
intScreenHeight = objItem.ScreenHeight
intScreenWidth = objItem.ScreenWidth
NextobjIE.Left = ( intScreenWidth - objIE.Width ) \ 2
objIE.Top = ( intScreenHeight - objIE.Height ) \ 2
' Insert the HTML code to prompt for user inputstrHTML = "<div style=""font-family: sans-serif; text-align: center; margin-left: auto; margin-right: auto;"">\n" _
& "<table>\n" _
& "<tr>\n" _
& "\t<td colspan=""3""> </td>\n" _
& "<tr>\n" _
& "\t<td>Name:</td>\n" _
& "\t<td> </td>\n" _
& "\t<td><input type=""text"" size=""20"" autocomplete=""off"" id=""LoginName"" value=""" & strName _
& """ onkeyup=""javascript:if(event.keyCode==13){document.getElementById('Password').focus();}"" /></td>\n" _
& "</tr>\n" _
& "<tr>\n" _
& "\t<td>Password:</td>\n" _
& "\t<td> </td>\n" _
& "\t<td><input type=""password"" size=""21"" id=""Password"" " _
& "onkeyup=""javascript:if(event.keyCode==13){document.getElementById('OK').value=1;}"" /></td>\n" _
& "</tr>\n" _
& "</table>\n" _
& "<p><input type=""hidden"" id=""OK"" name=""OK"" value=""0"" />" _
& "<input type=""button"" value="" OK "" onclick=""VBScript:OK.Value=1""></p>\n" _
& "</div>"
objIE.Document.Body.InnerHTML = Replace( Replace( strHTML, "\t", vbTab ), "\n", vbCrLf )
' Hide the scrollbarsobjIE.Document.Body.Style.overflow = "auto"
' Make the window visibleobjIE.Visible = True
' Set focus on the appropriate input fieldIf strName = "" Then
objIE.Document.All.LoginName.Focus
ElseobjIE.Document.All.Password.Focus
End If
' Wait till the OK button has been clickedDo While objIE.Document.All.OK.Value = 0
WScript.Sleep 200
' Error handling, by Denis St-PierreIf 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 ' Make the dialog activeSet wshShell = CreateObject( "WScript.Shell" )
wshShell.AppActivate strDialogTitle
Set wshShell = Nothing
' Read the user input from the dialog windowIELogin = Array( objIE.Document.All.LoginName.Value, objIE.Document.All.Password.Value )
' Close and release the objectobjIE.Quit
Set objIE = Nothing
On Error Goto 0
End Function
page last modified: 2025-10-11; loaded in 0.0067 seconds