From: Robert S on
I am trying to write a script that gets a password from the user then
logs into a remote computer. The InputBox function doesn't seem to have
an option that masks the user input with other characters (eg. "*").
How can I do this?

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.
From: Tom Lavedas on
On Feb 16, 11:21 pm, Robert S <robert.spam.me.sensel...(a)gmail.com>
wrote:
> I am trying to write a script that gets a password from the user then
> logs into a remote computer.  The InputBox function doesn't seem to have
> an option that masks the user input with other characters (eg. "*").  
> How can I do this?
>
> 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 <tlavedas(a)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>&nbsp" & sPrompt & "<b>&nbsp</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;'>" _
& "&nbsp;Okay&nbsp;" _
& "</button> &nbsp; <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
From: mr_unreliable on
Robert S wrote:
> I am trying to write a script that gets a password from the user then
> logs into a remote computer. The InputBox function doesn't seem to have
> an option that masks the user input with other characters (eg. "*").
> How can I do this?
>

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)


From: Tom Lavedas on
On Feb 17, 2:18 pm, mr_unreliable <kindlyReplyToNewsgr...(a)notmail.com>
wrote:
> Robert S wrote:
> > I am trying to write a script that gets a password from the user then
> > logs into a remote computer.  The InputBox function doesn't seem to have
> > an option that masks the user input with other characters (eg. "*").  
> > How can I do this?
>
> 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
From: Robert S on
>> I am trying to write a script that gets a password from the user then
>> logs into a remote computer. The InputBox function doesn't seem to have
>> an option that masks the user input with other characters (eg. "*").
>> How can I do this?
> 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 ...
>

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