Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for ieuserin.vbs

(view source code of ieuserin.vbs as plain text)

  1. strUserInput = GetUserInput( "Please enter your name:" )
  2. WScript.Echo "Your name is: " & strUserInput
  3.  
  4. Function GetUserInput( myPrompt )
  5. ' This function uses Internet Explorer to
  6. ' create a dialog and prompt for user input.
  7. '
  8. ' Version:             2.11
  9. ' Last modified:       2013-11-07
  10. '
  11. ' Argument:   [string] prompt text, e.g. "Please enter your name:"
  12. ' Returns:    [string] the user input typed in the dialog screen
  13. '
  14. ' Written by Rob van der Woude
  15. ' http://www.robvanderwoude.com
  16. ' Error handling code written by Denis St-Pierre
  17. 	Dim objIE
  18.  
  19. 	' Create an IE object
  20. 	Set objIE = CreateObject( "InternetExplorer.Application" )
  21.  
  22. 	' Specify some of the IE window's settings
  23. 	objIE.Navigate "about:blank"
  24. 	objIE.Document.title = "Input required " & String( 100, "." )
  25. 	objIE.ToolBar        = False
  26. 	objIE.Resizable      = False
  27. 	objIE.StatusBar      = False
  28. 	objIE.Width          = 320
  29. 	objIE.Height         = 180
  30.  
  31. 	' Center the dialog window on the screen
  32. 	With objIE.Document.parentWindow.screen
  33. 		objIE.Left = (.availWidth  - objIE.Width ) \ 2
  34. 		objIE.Top  = (.availheight - objIE.Height) \ 2
  35. 	End With
  36.  
  37. 	' Wait till IE is ready
  38. 	Do While objIE.Busy
  39. 		WScript.Sleep 200
  40. 	Loop
  41. 	' Insert the HTML code to prompt for user input
  42. 	objIE.Document.body.innerHTML = "<div align=""center""><p>" & myPrompt _
  43. 	                              & "</p>" & vbCrLf _
  44. 	                              & "<p><input type=""text"" size=""20"" " _
  45. 	                              & "id=""UserInput""></p>" & vbCrLf _
  46. 	                              & "<p><input type=""hidden"" id=""OK"" " _
  47. 	                              & "name=""OK"" value=""0"">" _
  48. 	                              & "<input type=""submit"" value="" OK "" " _
  49. 	                              & "OnClick=""VBScript:OK.value=1""></p></div>"
  50. 	' Hide the scrollbars
  51. 	objIE.Document.body.style.overflow = "auto"
  52. 	' Make the window visible
  53. 	objIE.Visible = True
  54. 	' Set focus on input field
  55. 	objIE.Document.all.UserInput.focus
  56.  
  57. 	' Wait till the OK button has been clicked
  58. 	On Error Resume Next
  59. 	Do While objIE.Document.all.OK.value = 0 
  60. 		WScript.Sleep 200
  61. 		' Error handling code by Denis St-Pierre
  62. 		If Err Then ' user clicked red X (or alt-F4) to close IE window
  63. 			IELogin = Array( "", "" )
  64. 			objIE.Quit
  65. 			Set objIE = Nothing
  66. 			Exit Function
  67. 		End if
  68. 	Loop
  69. 	On Error Goto 0
  70.  
  71.  
  72. 	' Read the user input from the dialog window
  73. 	GetUserInput = objIE.Document.all.UserInput.value
  74.  
  75. 	' Close and release the object
  76. 	objIE.Quit
  77. 	Set objIE = Nothing
  78. End Function
  79.  

page last modified: 2024-04-16; loaded in 0.0062 seconds