You are not logged in.

#1 13 Apr 2016 17:23

paul0041
Member
Registered: 19 Mar 2015
Posts: 21

determining if account is password protected

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

#2 13 Apr 2016 19:54

paul0041
Member
Registered: 19 Mar 2015
Posts: 21

Re: determining if account is password protected

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

#3 13 Apr 2016 23:11

paul0041
Member
Registered: 19 Mar 2015
Posts: 21

Re: determining if account is password protected

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

Board footer

Powered by