For ease of distribution I'd like to be able to do this in a single
script - rather than using a separate library or other file.
TIA.
This is not possible without a third party control. One approach
often used, however, is to use the ubiquitous presence of IE as the
third party control to implement a password box, something like this
often posted old sample of mine ...
' script
' Requires WScript version 5.1+
' Tom Lavedas <tlav...@hotmail.com>
' with help from and thanks to Joe Ernest and
' Michael Harris
'
' modified 1/2008 to handle IE7+
'
Function PasswordBox(sPrompt, sDefault)
set oIE = CreateObject("InternetExplorer.Application")
With oIE
' Configure the IE window
.RegisterAsDropTarget = False
.statusbar = false : .toolbar = false
.menubar = false : .addressbar = false
.Resizable = False
.Navigate "about:blank"
Do Until .ReadyState = 4 : WScript.Sleep 50 : Loop
' Test for IE 7 - cannot remove 'chrome' in that version
nVersion = CSng(replace(split(_
.document.parentWindow.navigator.appVersion, " ")(3)_
, ";", ""))
if nVersion < 7.0 Then .FullScreen = True
.width = 400 : .height = 270
' Create the password box document
With .document
oIE.left = .parentWindow.screen.width \ 2 - 200
oIE.top = .parentWindow.screen.height\ 2 - 100
.open
.write "<html><head><" & "script>bboxwait=true;</" _
& "script><title>Password _</title></head>"_
& "<body bgColor=silver scroll=no " _
& "language=vbs style='border-" _
& "style:outset;border-Width:3px'" _
& " onHelp='window.event.returnvalue=false" _
& ":window.event.cancelbubble=true'" _
& " oncontextmenu=" _
& "'window.event.returnvalue=false" _
& ":window.event.cancelbubble=true'" _
& " onkeydown='if ((window.event.keycode>111)"_
& " and (window.event.keycode<117)) or" _
& " window.event.ctrlkey then" _
& " window.event.keycode=0" _
& ":window.event.cancelbubble=true" _
& ":window.event.returnvalue=false'" _
& " onkeypress='if window.event.keycode=13" _
& " then bboxwait=false'><center>" _
& "<div style='padding:10px;background-color:lightblue'>" _
& "<b> " & sPrompt & "<b> </div><p>" _
& "<table bgcolor=cornsilk cellspacing=10><tr><td>" _
& " <b>User:</b></td><td>" _
& "<input type=text size=10 id=user value='" _
& sDefault & "'>" _
& "</td><tr><td> <b>Password:</b></td><td>" _
& "<input type=password size=12 id=pass>" _
& "</td></tr></table><br>" _
& "<button onclick='bboxwait=false;'>" _
& " Okay " _
& "</button> <button onclick=" _
& "'document.all.user.value=""CANCELLED"";" _
& "document.all.pass.value="""";" _
& "bboxwait=false;'>Cancel" _
& "</button></center></body></html>"
.close
Do Until .ReadyState = "complete" : WScript.Sleep 100 : Loop
.all.user.focus
.all.user.select ' Optional
oIE.Visible = True
CreateObject("Wscript.Shell")_
.Appactivate "Password _"
PasswordBox = Array("CANCELLED")
On Error Resume Next
Do While .parentWindow.bBoxWait
if Err Then Exit Function
WScript.Sleep 100
Loop
oIE.Visible = False
PasswordBox = Array(.all.user.value, .all.pass.value)
End With ' document
End With ' IE
End Function
_____________________
Tom Lavedas
If the systems you are responsible for have some version of
msOfc installed (with VBA), then you will most likely also
have ms "Forms 2.0" installed. (Look for fm20.dll).
If you do have ms "Forms 2.0", then you can use the textbox
control that is included in fm20.dll with your hta, and set
the password mask character to whatever you want. The
following example is using an asterisk pw char.
--- <code> ---
<OBJECT ID="TextBox1" WIDTH=96 HEIGHT=24
CLASSID="CLSID:8BD21D10-EC42-11CE-9E0D-00AA006002F3">
<PARAM NAME="VariousPropertyBits" VALUE="746604571">
<PARAM NAME="Size" VALUE="2540;635">
<PARAM NAME="PasswordChar" VALUE="42">
<PARAM NAME="FontCharSet" VALUE="0">
<PARAM NAME="FontPitchAndFamily" VALUE="2">
<PARAM NAME="FontWeight" VALUE="0">
</OBJECT>
--- </code> ---
cheers, jw
____________________________________________________________
You got questions? WE GOT ANSWERS!!! ..(but, no guarantee
the answers will be applicable to the questions)
This still needs a 'console' in which to be instantiated. I assume
you mean it to be IE. If it is IE, then your approach requires two
third party controls to be installed; that is, IE (always present on
US Win based machines) and some version of MS Office. I don't see the
advantage over using the HTML password input control.
_____________________
Tom Lavedas
Hi.
This seems to do the trick. Now I need to get rid of the "User" prompt
because its not needed. Hopefully won't be too difficult
Not too tricky. Remove these three lines from the display page
setup ...
& " <b>User:</b></td><td>" _
& "<input type=text size=10 id=user value='" _
& sDefault & "'>" _
And remove the User return value from the return array. Maybe by
changing these two lines ...
PasswordBox = Array("CANCELLED")
...
PasswordBox = Array(.all.user.value, .all.pass.value)
To this ,,,
PasswordBox = "CANCELLED"
...
PasswordBox = .all.pass.value
_____________________
Tom Lavedas
You may say that your "steak" is superior to my "hamburger".
That doesn't mean that "hamburger" should never be
mentioned in polite society.
cheers, jw