Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for iepwddlg.vbs

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

  1. Option Explicit
  2.  
  3. Dim strPw
  4.  
  5. strPw = GetPassword( "Please enter your password:" )
  6. WScript.Echo "Your password is: " & strPw
  7.  
  8. Function GetPassword( myPrompt )
  9. ' This function uses Internet Explorer to
  10. ' create a dialog and prompt for a password.
  11. '
  12. ' Version:             2.15
  13. ' Last modified:       2015-10-19
  14. '
  15. ' Argument:   [string] prompt text, e.g. "Please enter password:"
  16. ' Returns:    [string] the password typed in the dialog screen
  17. '
  18. ' Written by Rob van der Woude
  19. ' http://www.robvanderwoude.com
  20. ' Error handling code written by Denis St-Pierre
  21. 	Dim blnFavoritesBar, blnLinksExplorer, objIE, strHTML, strRegValFB, strRegValLE, wshShell
  22.  
  23. 	blnFavoritesBar  = False
  24. 	strRegValFB = "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MINIE\LinksBandEnabled"
  25. 	blnLinksExplorer = False
  26. 	strRegValLE = "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\LinksExplorer\Docked"
  27.  
  28. 	Set wshShell = CreateObject( "WScript.Shell" )
  29.  
  30. 	On Error Resume Next
  31. 	' Temporarily hide IE's Favorites Bar if it is visible
  32. 	If wshShell.RegRead( strRegValFB ) = 1 Then
  33. 		blnFavoritesBar = True
  34. 		wshShell.RegWrite strRegValFB, 0, "REG_DWORD"
  35. 	End If
  36. 	' Temporarily hide IE's Links Explorer if it is visible
  37. 	If wshShell.RegRead( strRegValLE ) = 1 Then
  38. 		blnLinksExplorer = True
  39. 		wshShell.RegWrite strRegValLE, 0, "REG_DWORD"
  40. 	End If
  41. 	On Error Goto 0
  42.  
  43. 	' Create an IE object
  44. 	Set objIE = CreateObject( "InternetExplorer.Application" )
  45. 	' specify some of the IE window's settings
  46. 	objIE.Navigate "about:blank"
  47. 	' Add string of "invisible" characters (500 tabs) to clear the title bar
  48. 	objIE.Document.title = "Password " & String( 500, 7 )
  49. 	objIE.AddressBar     = False
  50. 	objIE.Resizable      = False
  51. 	objIE.StatusBar      = False
  52. 	objIE.ToolBar        = False
  53. 	objIE.Width          = 320
  54. 	objIE.Height         = 180
  55. 	' Center the dialog window on the screen
  56. 	With objIE.Document.parentWindow.screen
  57. 		objIE.Left = (.availWidth  - objIE.Width ) \ 2
  58. 		objIE.Top  = (.availheight - objIE.Height) \ 2
  59. 	End With
  60. 	' Wait till IE is ready
  61. 	Do While objIE.Busy
  62. 		WScript.Sleep 200
  63. 	Loop
  64. 	' Insert the HTML code to prompt for a password
  65. 	strHTML = "<div style=""text-align: center;"">" _
  66. 	        & "<p>" & myPrompt & "</p>" _
  67. 	        & "<p><input type=""password"" size=""20"" id=""Password"" onkeyup=" _
  68. 	        & """if(event.keyCode==13){document.all.OKButton.click();}"" /></p>" _
  69. 	        & "<p><input type=""hidden"" id=""OK"" name=""OK"" value=""0"" />" _
  70. 	        & "<input type=""submit"" value="" OK "" id=""OKButton"" " _
  71. 	        & "onclick=""document.all.OK.value=1"" /></p>" _
  72. 	        & "</div>"
  73. 	objIE.Document.body.innerHTML = strHTML
  74. 	' Hide the scrollbars
  75. 	objIE.Document.body.style.overflow = "auto"
  76. 	' Make the window visible
  77. 	objIE.Visible = True
  78. 	' Set focus on password input field
  79. 	objIE.Document.all.Password.focus
  80.  
  81. 	' Wait till the OK button has been clicked
  82. 	On Error Resume Next
  83. 	Do While objIE.Document.all.OK.value = 0 
  84. 		WScript.Sleep 200
  85. 		' Error handling code by Denis St-Pierre
  86. 		If Err Then	' User clicked red X (or Alt+F4) to close IE window
  87. 			GetPassword = ""
  88. 			objIE.Quit
  89. 			Set objIE = Nothing
  90. 			' Restore IE's Favorites Bar if applicable
  91. 			If blnFavoritesBar Then wshShell.RegWrite strRegValFB, 1, "REG_DWORD"
  92. 			' Restore IE's Links Explorer if applicable
  93. 			If blnLinksExplorer Then wshShell.RegWrite strRegValLE, 1, "REG_DWORD"
  94. 			' Use "WScript.Quit 1" instead of "Exit Function" if you want
  95. 			' to abort with return code 1 in case red X or Alt+F4 were used
  96. 			Exit Function
  97. 		End if
  98. 	Loop
  99. 	On Error Goto 0
  100.  
  101. 	' Read the password from the dialog window
  102. 	GetPassword = objIE.Document.all.Password.value
  103.  
  104. 	' Terminate the IE object
  105. 	objIE.Quit
  106. 	Set objIE = Nothing
  107.  
  108. 	On Error Resume Next
  109. 	' Restore IE's Favorites Bar if applicable
  110. 	If blnFavoritesBar Then wshShell.RegWrite strRegValFB, 1, "REG_DWORD"
  111. 	' Restore IE's Links Explorer if applicable
  112. 	If blnLinksExplorer Then wshShell.RegWrite strRegValLE, 1, "REG_DWORD"
  113. 	On Error Goto 0
  114.  
  115. 	Set wshShell = Nothing
  116. End Function
  117.  

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