Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hiding the password in VBScrip InputBox

Status
Not open for further replies.

keybrdcowboy

IS-IT--Management
Aug 31, 2004
96
US
Well, I have been reaserching this for a day now, and from what I have been reading, it's not possible to hide the password using just VBscript. (For background purposes, I am prompting the user for a username and password which then connects to AD using those credintials) It works fine right now just have the user type in the info using Input Boxes, but I would like for the password to be starred out, or hidden, so someon sitting behind the user can't see it. I have tried using one dll thing I found ont he internet, but now I get a type mismatch error, and I can't figure out why. Can anyone help, or provide a different solution? Thanks a lot. You guys have come through for me before, so I'm trying again. Here's the code.


' Sets the script up to manipulate files
Set fso = CreateObject("Scripting.FileSystemObject")

' Sets the path to the textfile to read from
Set readfile = fso_OpenTextFile("c:\documents and settings\mobleyj\desktop\usernametest.txt")

' Reads the contents of the file into an array named arrBadUsernames
iUpperBound = 0
While Not readfile.AtEndOfStream
ReDim Preserve arrBadUsernames(iUpperBound)
arrBadUsernames(UBound(arrBadUsernames)) = readfile.ReadLine
iUpperBound = iUpperBound + 1
Wend

' Closes the connection to the file
readfile.Close

' Sets the domain the script is working in
strDomain = "domain"

set objLogon = CreateObject("PassDlg.LogonDialog")
objLogon.ShowDialog "Enter your administrative username and password:"
objCancelled = objLogon.Canceled
objlogon.AllowBlankUsername = False
objLogon.AllowBlankPassword = False
objCancelled = objLogon.Canceled
strUsername = objLogon.Username
strPassword = objLogon.Password
If objCancelled Then
wscript.quit
End If

wscript.echo strUsername
wscript.echo strPassword
wscript.echo strDomain

' Pops up a message box asking for the username and password to use to connect to active directory
'strUsername = inputbox("Please type in your administrative username:", "AdminUsername")
' If strUsername = "" Then
' wscript.quit
'End If
'strPassword = inputbox("Please type in your administrative password:", "AdminPassword")
' If strPassword = "" Then
' wscript.quit
' End If

' Tells the script to take all the names that were in the text file, and one at a time, set the account
' so that the user has to change their password at next logon

For Each entry in arrBadUsernames
' Makes the connection to Active Directory using the username and password the user specified
Set objIADS = GetObject("WinNT:").OpenDSObject("WinNT://" & strDomain, strUsername, strPassword, ADS_SECURE_AUTHENTICATION)

'The code below actually does the manipulating of the user accounts, then clears all the variables
Set oUser = objIADS.GetObject("user", entry)
oUser.put "PasswordExpired",1
oUser.SetInfo
set oUser = Nothing
set strUsername = Nothing
set strPassword = Nothing
Next



 
As an update, I have figured out that the problem has something to do with the variables. If I hard code a username and password in there, then it works fine. Any ideas???
 
Remove these 2 lines:
set strUsername = Nothing
set strPassword = Nothing


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hello keybrdcowboy,

Also control the type by this.
[tt]
Set objIADS = GetObject("WinNT:").OpenDSObject("WinNT://" & strDomain, cstr(strUsername), cstr(strPassword), ADS_SECURE_AUTHENTICATION)
[/tt]
Also I hope constants are defined somewhere up there.
[tt]
const ADS_SECURE_AUTHENTICATION=&h01
[/tt]
regards - tsuji
 
keybrdcowboy,

I use Bill Stewart's excellent freeware third-party dll all the time. 'PassDlg.dll' can be obtained from Add it to the system folder then register it to use.

Below is another example to popup a dialog asking for the Administrator password before running 'Add/Remove Programs' as Administrator.

Code:
Dim WSH, AdminPassWrd, PassDlg, prog
Set WSH = WScript.CreateObject("WScript.Shell")
Set PassDlg = CreateObject("PassDlg.PasswordDialog")
PassDlg.ShowDialog "Administrator password required"
AdminPassWrd = PassDlg.Password
prog = "runas.exe /env /user:Administrator "
prog = prog & """Control %systemRoot%\system32\appwiz.cpl,System"""
WSH.Run prog,2,false
WScript.Sleep 500
WSH.Sendkeys AdminPassWrd
WSH.Sendkeys "~"

'Finish up
Set WSH = Nothing
Set PassDlg = Nothing

Hope this helps...

Rick
 
Thanks for all the replies.... I ended up using that PassDLG thing...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top