Link to home
Start Free TrialLog in
Avatar of MDauphinais1
MDauphinais1

asked on

Mask password Inputbox in VBScript

I have a VBScript that prompts users for a username and password and then passes the information to log them into a remote server. Is it possible to mask the password as it is entered into the input box?
Avatar of nayernaguib
nayernaguib
Flag of Egypt image

Try the following script (you need to run it using CScript host):

  Set oScriptPW = CreateObject("ScriptPW.Password")
  WScript.StdOut.Write "Type password and press the Enter key: "
  strPassword = oScriptPW.GetPassword()
  WScript.StdOut.WriteLine vbCrLf & "You entered: " & strPassword

_______________

  Nayer Naguib
Avatar of MDauphinais1
MDauphinais1

ASKER

How do I run it using CScript?
I tried this but it didn't work...

Dim oShell
Set oShell = CreateObject("Wscript.Shell")

forceUseCScript

Sub forceUseCScript()
   
If Not WScript.FullName = WScript.Path & "\cscript.exe" Then

 Set oScriptPW = CreateObject("ScriptPW.Password")
  WScript.StdOut.Write "Type password and press the Enter key: "
  strPassword = oScriptPW.GetPassword()
  WScript.StdOut.WriteLine vbCrLf & "You entered: " & strPassword

      WScript.Quit 0
   End If
End Sub
Set objPassword = CreateObject("ScriptPW.Password")
WScript.StdOut.Write "Please enter your password:"

strPassword = objPassword.GetPassword()
Wscript.Echo
Wscript.Echo "Your password is: " & strPassword

To run the above code from cscript, do the following:
1) Paste the above code in a .vbs file and save it (ie: c:\documents and settings\user\desktop\mask.vbs)
2) Open a command prompt and change to the directory you saved the file in step 1 (ie: C:\documents and settings\user\desktop)
3) At the command prompt launch the script using cscript (ie: cscript mask.vbs)
4) This will echo back the password you typed.

Please note, this will only work for Windows XP and WIndows 2003.  If you are using other OS's, you'll need to create a .hta to accomplish this.  See the following link for more details:
http://www.microsoft.com/technet/scriptcenter/resources/qanda/feb05/hey0204.mspx
Add the following statements at the beginning of the script:

  If LCase(Right(Wscript.FullName, 11)) = "wscript.exe" Then
      strPath = Wscript.ScriptFullName
      strCommand = "%comspec% /k cscript  " & Chr(34) & strPath & chr(34)
      Set objShell = CreateObject("Wscript.Shell")
      objShell.Run(strCommand)
      Wscript.Quit
  End If

_______________

  Nayer Naguib
Does this have to use the command prompt? Is there no way to still use the Input box type format?
ASKER CERTIFIED SOLUTION
Avatar of deadite
deadite
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial