You are not logged in.
Hello, I need to determine if a user account is password protected.
It would be ideal if I could really check whether there is a password on the account or not, but I haven't been able to find a way in batch. This is part of a big package, so it isn't possible to change to powershell or vb.
Any ideas on how I might do this?
Last edited by paul0041 (13 Apr 2016 18:39)
Offline
I found a method that is almost what I need below. I could set a return value instead of Wscript.Echo and then call this from a batch file. The problem I don't know how to solve is just running this against the currently logged in user. Anybody know how I would do that?
On Error Resume Next
Set objNetwork=CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName
strPassword=""
Set colAccounts = GetObject("WinNT://" & strComputer)
colAccounts.Filter = Array("user")
For Each objUser In colAccounts
objUser.ChangePassword strPassword, strPassword
If Err = 0 or Err = -2147023569 Then
Wscript.Echo objUser.Name & " is using a blank password."
End If
Err.Clear
Next
Offline
solved:
If the password is blank, the script successfully changes it to blank - hence we know it was blank to begin with and script returns 3. If it wasn't blank and because of that, not able to change it, the script returns 1.
On Error Resume Next
strComputer = "."
strPassword = ""
returnValue = 1
set wshShell = CreateObject( "WScript.Shell" )
strUser = wshShell.ExpandEnvironmentStrings( "%USERNAME%" )
set objUser = GetObject("WinNT://" & strComputer & "/" & strUser )
objUser.ChangePassword strPassword, strPassword
If Err = 0 or Err = -2147023569 Then
returnValue = 3
End If
WScript.Quit( returnValue )
batch:
@echo off
Call passwordchk.vbs
If %ErrorLevel%==3 echo It worked!
pause
Offline