You are not logged in.

#1 13 Apr 2016 21:37

paul0041
Member
Registered: 19 Mar 2015
Posts: 21

Account password protected?

I am clueless in vbscript.  I am trying to find a way to see if the currently logged in account has a blank password.  I found the code below and the only bummer is that it checks all accounts.  I understand enough to set a return value instead of Wscript.Echo and then do Wscript.quit(returnvalue) to tell my batch script if the password is empty or not, but don't have a clue how to replace the Array and loop with UserName from the shell.  Can anyone help me?  Thanks much.

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

#2 13 Apr 2016 23:09

paul0041
Member
Registered: 19 Mar 2015
Posts: 21

Re: Account 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

Last edited by paul0041 (13 Apr 2016 23:10)

Offline

Board footer

Powered by