InputBox: how do I hide user input

  • Follow


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.
0
Reply Robert 2/17/2010 4:21:39 AM

On Feb 16, 11:21=A0pm, Robert S <robert.spam.me.sensel...@gmail.com>
wrote:
> I am trying to write a script that gets a password from the user then
> logs into a remote computer. =A0The InputBox function doesn't seem to hav=
e
> an option that masks the user input with other characters (eg. "*"). =A0
> 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@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 =3D CreateObject("InternetExplorer.Application")
  With oIE
' Configure the IE window
    .RegisterAsDropTarget =3D False
    .statusbar =3D false : .toolbar    =3D false
    .menubar   =3D false : .addressbar =3D false
    .Resizable =3D False
    .Navigate "about:blank"
    Do Until .ReadyState =3D 4 : WScript.Sleep 50 : Loop
' Test for IE 7 - cannot remove 'chrome' in that version
    nVersion  =3D CSng(replace(split(_
                .document.parentWindow.navigator.appVersion, " ")(3)_
                , ";", ""))
    if nVersion < 7.0 Then .FullScreen =3D True
    .width =3D 400       : .height =3D 270
' Create the password box document
    With .document
      oIE.left =3D .parentWindow.screen.width \ 2 - 200
      oIE.top  =3D .parentWindow.screen.height\ 2 - 100
      .open
      .write "<html><head><" & "script>bboxwait=3Dtrue;</" _
           & "script><title>Password _</title></head>"_
           & "<body bgColor=3Dsilver scroll=3Dno " _
           & "language=3Dvbs style=3D'border-" _
           & "style:outset;border-Width:3px'" _
           & " onHelp=3D'window.event.returnvalue=3Dfalse" _
           & ":window.event.cancelbubble=3Dtrue'" _
           & " oncontextmenu=3D" _
           & "'window.event.returnvalue=3Dfalse" _
           & ":window.event.cancelbubble=3Dtrue'" _
           & " onkeydown=3D'if ((window.event.keycode>111)"_
           & " and  (window.event.keycode<117)) or" _
           & " window.event.ctrlkey then" _
           & " window.event.keycode=3D0" _
           & ":window.event.cancelbubble=3Dtrue" _
           & ":window.event.returnvalue=3Dfalse'" _
           & " onkeypress=3D'if window.event.keycode=3D13" _
           & " then bboxwait=3Dfalse'><center>" _
           & "<div style=3D'padding:10px;background-color:lightblue'>" _
           & "<b>&nbsp" & sPrompt & "<b>&nbsp</div><p>" _
           & "<table bgcolor=3Dcornsilk cellspacing=3D10><tr><td>" _
           & " <b>User:</b></td><td>" _
           & "<input type=3Dtext size=3D10 id=3Duser value=3D'" _
           & sDefault & "'>" _
           & "</td><tr><td> <b>Password:</b></td><td>" _
           & "<input type=3Dpassword size=3D12 id=3Dpass>" _
           & "</td></tr></table><br>" _
           & "<button onclick=3D'bboxwait=3Dfalse;'>" _
           & "&nbsp;Okay&nbsp;" _
           & "</button> &nbsp; <button onclick=3D" _
           & "'document.all.user.value=3D""CANCELLED"";" _
           & "document.all.pass.value=3D"""";" _
           & "bboxwait=3Dfalse;'>Cancel" _
           & "</button></center></body></html>"
      .close
      Do Until .ReadyState =3D "complete" : WScript.Sleep 100 : Loop
      .all.user.focus
      .all.user.select ' Optional
      oIE.Visible =3D True
      CreateObject("Wscript.Shell")_
        .Appactivate "Password _"
      PasswordBox =3D Array("CANCELLED")
      On Error Resume Next
      Do While .parentWindow.bBoxWait
        if Err Then Exit Function
        WScript.Sleep 100
      Loop
      oIE.Visible =3D False
      PasswordBox =3D Array(.all.user.value, .all.pass.value)
    End With ' document
  End With   ' IE
End Function
_____________________
Tom Lavedas
0
Reply Tom 2/17/2010 1:39:10 PM


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)


0
Reply mr_unreliable 2/17/2010 7:15:17 PM

On Feb 17, 2:18=A0pm, mr_unreliable <kindlyReplyToNewsgr...@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. =A0The InputBox function doesn't seem to h=
ave
> > an option that masks the user input with other characters (eg. "*"). =
=A0
> > 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. =A0(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. =A0The
> following example is using an asterisk pw char.
>
> --- <code> ---
> <OBJECT ID=3D"TextBox1" WIDTH=3D96 HEIGHT=3D24
> =A0 CLASSID=3D"CLSID:8BD21D10-EC42-11CE-9E0D-00AA006002F3">
> =A0 =A0 =A0<PARAM NAME=3D"VariousPropertyBits" VALUE=3D"746604571">
> =A0 =A0 =A0<PARAM NAME=3D"Size" VALUE=3D"2540;635">
> =A0 =A0 =A0<PARAM NAME=3D"PasswordChar" VALUE=3D"42">
> =A0 =A0 =A0<PARAM NAME=3D"FontCharSet" VALUE=3D"0">
> =A0 =A0 =A0<PARAM NAME=3D"FontPitchAndFamily" VALUE=3D"2">
> =A0 =A0 =A0<PARAM NAME=3D"FontWeight" VALUE=3D"0">
> </OBJECT>
> --- </code> ---
>
> cheers, jw
> ____________________________________________________________
>
> You got questions? =A0WE GOT ANSWERS!!! =A0..(but, no guarantee
> =A0 =A0 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
0
Reply Tom 2/17/2010 8:33:05 PM

>> 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 

0
Reply Robert 2/17/2010 9:00:14 PM

On Feb 17, 4:00=A0pm, "Robert S" <robert.spam.me.sensel...@gmail.com>
wrote:
> >> I am trying to write a script that gets a password from the user then
> >> logs into a remote computer. =A0The 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. =A0One 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. =A0Now I need to get rid of the "User" prompt
> because its not needed. =A0Hopefully won't be too difficult

Not too tricky.  Remove these three lines from the display page
setup ...

           & " <b>User:</b></td><td>" _
           & "<input type=3Dtext size=3D10 id=3Duser value=3D'" _
           & sDefault & "'>" _

And remove the User return value from the return array.  Maybe by
changing these two lines ...

    PasswordBox =3D Array("CANCELLED")
....
    PasswordBox =3D Array(.all.user.value, .all.pass.value)

To this ,,,

    PasswordBox =3D "CANCELLED"
....
    PasswordBox =3D .all.pass.value
_____________________
Tom Lavedas
0
Reply Tom 2/17/2010 9:44:46 PM

Tom Lavedas wrote:
> I don't see the advantage over using
> the HTML password input control.
> 

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
0
Reply mr_unreliable 2/18/2010 6:52:15 PM

6 Replies
2146 Views

(page loaded in 0.164 seconds)

Similiar Articles:
















7/19/2012 9:38:07 PM


Reply: